fix: PWA not working after CRA@5 update (#6012)

* fix: PWA not working after CRA@5 update

* fix: fallback to default locale when fetch fails
This commit is contained in:
David Luzar 2022-12-18 22:23:30 +01:00 committed by GitHub
parent 73a45e1988
commit 95d669390f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 282 additions and 128 deletions

View file

@ -90,9 +90,14 @@ export const setLanguage = async (lang: Language) => {
if (lang.code.startsWith(TEST_LANG_CODE)) {
currentLangData = {};
} else {
currentLangData = await import(
/* webpackChunkName: "locales/[request]" */ `./locales/${currentLang.code}.json`
);
try {
currentLangData = await import(
/* webpackChunkName: "locales/[request]" */ `./locales/${currentLang.code}.json`
);
} catch (error: any) {
console.error(`Failed to load language ${lang.code}:`, error.message);
currentLangData = fallbackLangData;
}
}
};