言語設定の初期値がおかしい不具合を修正
This commit is contained in:
parent
2422edcbd4
commit
334037b161
2 changed files with 6 additions and 4 deletions
|
@ -15,15 +15,17 @@ import 'dayjs/locale/ja';
|
|||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
if (!localStorage[LOCALSTORAGE_KEY_LANG]) {
|
||||
localStorage[LOCALSTORAGE_KEY_LANG] = getBrowserLanguage();
|
||||
let lng = localStorage[LOCALSTORAGE_KEY_LANG];
|
||||
|
||||
if (!lng) {
|
||||
lng = localStorage[LOCALSTORAGE_KEY_LANG] = getBrowserLanguage();
|
||||
}
|
||||
|
||||
i18n
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources,
|
||||
lng: localStorage[LOCALSTORAGE_KEY_LANG],
|
||||
lng,
|
||||
interpolation: {
|
||||
escapeValue: false // Reactは常にXSS対策をしてくれるので、i18next側では対応不要
|
||||
}
|
||||
|
|
|
@ -31,5 +31,5 @@ export type LanguageCode = keyof typeof resources;
|
|||
|
||||
export const getBrowserLanguage = () => {
|
||||
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';
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue