Skip to content

Commit

Permalink
feat: 🎸 Fallback language (kolplattformen#7)
Browse files Browse the repository at this point in the history
If language does not exist, it falls back top first language in list
  • Loading branch information
JohanObrink authored Apr 26, 2021
1 parent b6137ab commit e944468
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ interface RawTranslation extends Translation {
specialLanguages: Repo
}

export type Language = 'sv' | 'en'
const languageList = ['sv', 'en']
export type Language = typeof languageList[number]
type Translations = Record<Language, RawTranslation>

const translations: Translations = {
sv: require('./sv.json'),
en: require('./en.json'),
}
const translations: Translations = languageList.reduce(
(map, lang) => ({
...map,
[lang]: require(`./${lang}.json`),
}),
{}
)

const translate = (lang: Language): Translation => {
const selectedLanguage = languageList.includes(lang) ? lang : languageList[0]
const {
subjects,
traningsskolaSubjects,
specialLanguages,
languages,
categories,
misc,
} = translations[lang]
} = translations[selectedLanguage]

return {
subjects,
Expand Down

0 comments on commit e944468

Please sign in to comment.