0
0
Fork 0

言語設定の初期値がおかしい不具合を修正

This commit is contained in:
Xeltica 2022-06-23 00:12:46 +09:00
parent 2422edcbd4
commit 334037b161
2 changed files with 6 additions and 4 deletions

View file

@ -15,15 +15,17 @@ import 'dayjs/locale/ja';
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
if (!localStorage[LOCALSTORAGE_KEY_LANG]) { let lng = localStorage[LOCALSTORAGE_KEY_LANG];
localStorage[LOCALSTORAGE_KEY_LANG] = getBrowserLanguage();
if (!lng) {
lng = localStorage[LOCALSTORAGE_KEY_LANG] = getBrowserLanguage();
} }
i18n i18n
.use(initReactI18next) .use(initReactI18next)
.init({ .init({
resources, resources,
lng: localStorage[LOCALSTORAGE_KEY_LANG], lng,
interpolation: { interpolation: {
escapeValue: false // Reactは常にXSS対策をしてくれるので、i18next側では対応不要 escapeValue: false // Reactは常にXSS対策をしてくれるので、i18next側では対応不要
} }

View file

@ -31,5 +31,5 @@ export type LanguageCode = keyof typeof resources;
export const getBrowserLanguage = () => { export const getBrowserLanguage = () => {
const lang = navigator.language.replace('-', '_').toLowerCase(); const lang = navigator.language.replace('-', '_').toLowerCase();
return (Object.keys(resources) as LanguageCode[]).map(l => l.toLowerCase()).find(k => k.startsWith(lang)) ?? 'en_US'; return (Object.keys(resources) as LanguageCode[]).find(k => k.toLowerCase().startsWith(lang)) ?? 'en_US';
}; };