And so had a little digging in the sources. /admin/admin/src/components/LanguageProvider
The problem is that one part of the application writes the locale just as a value and the other part (I have no idea where it happens) with stringify.
And when the initialization function tries to get a locale, it can’t find the “uk” locale in the list, so it fails.
I think it’s a small but very annoying bug if you use a non-standard locale.
So my temporary solution is.
In init.js
import localStorageKey from './utils/localStorageKey';
const init = (localeNames) => {
// Specifiy default en
let languageFromLocaleStorage = 'en'
// try get locale and remove quotes, else set storage to default
try {
languageFromLocaleStorage = window.localStorage.getItem(localStorageKey)?.replaceAll('"', '');
}catch {
window.localStorage.setItem(localStorageKey, JSON.stringify(languageFromLocaleStorage));
}
const appLanguage = localeNames[languageFromLocaleStorage] ? languageFromLocaleStorage : 'en';
return {
locale: appLanguage,
localeNames,
};
};
export default init;
In index.js
// Just add stringify to locale set item
useEffect(() => {
// Set user language in local storage.
window.localStorage.setItem(localStorageKey, JSON.stringify(locale));
document.documentElement.setAttribute('lang', locale);
}, [locale]);
And create patch with patch package