Skip to content

Commit

Permalink
activate detected language only if translations are available (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonukai authored Mar 12, 2022
1 parent 3cc38f0 commit fe5b4bb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions client/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ import { messages as en } from 'src/i18n/locales/en/translation';
import { messages as es } from 'src/i18n/locales/es/translation';

export const setupI18n = () => {
const locale = detect(fromNavigator(), 'en').split('-')?.at(0) || 'en';
const allMessages = {
da: da,
de: de,
en: en,
es: es,
};

const supportedLanguages = Object.keys(allMessages);

const detectedLocale = detect(fromNavigator(), 'en').split('-')?.at(0);

const locale = supportedLanguages.includes(detectedLocale)
? detectedLocale
: 'en';

i18n.loadLocaleData({
[locale]: { plurals: plurals[locale] },
});
i18n.load({ da: da, de: de, en: en, es: es });
i18n.load(allMessages);
i18n.activate(locale);
};

0 comments on commit fe5b4bb

Please sign in to comment.