Files
suwayomi-material-you-webui/src/i18n/index.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-13 20:20:08 +03:30
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2023-02-13 20:20:08 +03:30
import { i18n } from '@lingui/core';
2026-01-22 00:12:22 +01:00
import { detectLocale } from '@/lib/ISOLanguageUtil.ts';
import localesConfig from '@/i18n/locales.json';
export const i18nResources = localesConfig.locales;
2024-04-24 23:56:06 +02:00
export type I18nResourceCode = (typeof i18nResources)[number];
2023-02-13 20:20:08 +03:30
const DEFAULT_LOCALE = localesConfig.defaultLocale;
export async function loadCatalog(locale: string): Promise<void> {
const localeToLoad = i18nResources.includes(locale as (typeof i18nResources)[number]) ? locale : DEFAULT_LOCALE;
const { messages } = await import(`./locales/${localeToLoad}.po`);
i18n.loadAndActivate({ locale: localeToLoad, messages });
}
export async function initializeLocalization(): Promise<void> {
try {
await loadCatalog(detectLocale());
} catch (e) {
await loadCatalog(DEFAULT_LOCALE);
}
}
export { i18n };