import React from "react";
import { useLocation } from "react-router-dom";
import useSWR from "swr";
import { Doc } from "../../../libs/types";
import NoteCard from "../ui/molecules/notecards";
import LANGUAGES_RAW from "../../../libs/languages";
import { RETIRED_LOCALES } from "../../../libs/constants";
import { useLocale } from "../hooks";
const LANGUAGES = new Map(
Object.entries(LANGUAGES_RAW).map(([locale, data]) => {
return [locale.toLowerCase(), data];
})
);
// TODO IDEA
// Use https://www.npmjs.com/package/string-similarity
// to download the /$locale/search-index.json to get a list of all possible
// URLs and see if we can compare the current URL with one of those
// for making a great suggestion,
// like "Did you mean: $doctitle?"
export default function FallbackLink({ url }: { url: string }) {
const locale = useLocale();
const location = useLocation();
const [fallbackCheckURL, setFallbackCheckURL] = React.useState
Unfortunately, when trying to look to see if there was an English
fallback, that check failed. This is either because of a temporary
network error or because of a bug.
The error was:
The page you requested doesn't exist in{" "}
{LANGUAGES.get(locale.toLowerCase())?.English} but it exists in{" "}
English
The{" "}
{LANGUAGES.get(locale.toLowerCase())?.English} ({locale})
{" "}
locale has been retired, and this page doesn't exist in English.
You may find an archived version of this page in one of these
repositories:
Oh no!
{error.toString()}
Good news!
The page you requested doesn't exist, but you could try a site search for:
{part}