Handle unsupported dayjs locales

DayJs doesn't support all the locales returned by "navigator.language"
This commit is contained in:
schroda
2024-06-25 17:11:33 +02:00
parent 1e39619314
commit 17e2d7585d
10 changed files with 418 additions and 220 deletions

View File

@@ -7,7 +7,7 @@
*/
import { t } from 'i18next';
import { ISOLanguage, ISOLanguages, loadDefaultDayJsLocale } from '@/util/isoLanguages.ts';
import { ISOLanguage, ISOLanguages } from '@/util/isoLanguages.ts';
export enum DefaultLanguage {
ALL = 'all',
@@ -78,20 +78,3 @@ export const langSortCmp = (a: string, b: string) => {
return aLang > bLang ? 1 : -1;
};
export const loadDayJsLocale = async (locale: string) => {
const lang = getISOLanguage(locale);
try {
if (!lang) {
await loadDefaultDayJsLocale();
return false;
}
await lang.dayjsImport();
return true;
} catch (e) {
return false;
// ignore - dayjs falls back to en anyway
}
};