-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new NavigationLink collection for navbar, allow language override…
… in useTranslate to account for changing language
- Loading branch information
Showing
8 changed files
with
101 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import translations from "./translations.json"; | ||
import { Language, useLanguage } from "../lib/LanguageContext"; | ||
|
||
type TranslationKey = keyof typeof translations; | ||
export type TranslationKey = keyof typeof translations; | ||
|
||
const translate = | ||
(language: Language) => | ||
(key: TranslationKey): string => { | ||
const translation = translations[key]; | ||
const translate = (key: TranslationKey, language: Language): string => { | ||
const translation = translations[key]; | ||
|
||
if (translation === undefined) { | ||
throw new Error( | ||
`Could not find translation ${key} (something is very wrong)`, | ||
); | ||
} | ||
if (translation === undefined) { | ||
throw new Error( | ||
`Could not find translation ${key} (try running "npm run fetchTranslations")`, | ||
); | ||
} | ||
|
||
return translation[language]; | ||
}; | ||
return translation[language]; | ||
}; | ||
|
||
const useTranslate = () => { | ||
const { language } = useLanguage(); | ||
return translate(language); | ||
return (key: TranslationKey, languageOverride?: Language) => | ||
translate(key, languageOverride ?? language); | ||
}; | ||
|
||
export default useTranslate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters