/* * 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/. */ import { i18n } from '@lingui/core'; import { detectLocale, SELECTED_LANGUAGE_CODE_KEY } from '@/lib/ISOLanguageUtil.ts'; import { AppStorage } from '@/lib/storage/AppStorage.ts'; // This array is auto-generated by tools/scripts/weblate/generatei18nResources.ts. Do not edit manually. export const i18nResources = [ 'de', 'en', 'es', 'fa', 'fr', 'hu', 'it', 'ja', 'ko', 'pl', 'pt', 'ru', 'ta', 'tr', 'vi', 'zh_Hans', 'zh_Hant', ] as const; export type I18nResourceCode = (typeof i18nResources)[number]; const DEFAULT_LOCALE = 'en'; export async function loadCatalog(locale: string): Promise { const localeToLoad = i18nResources.includes(locale as (typeof i18nResources)[number]) ? locale : DEFAULT_LOCALE; const { messages } = await import(`./locales/${localeToLoad}.po`); i18n.loadAndActivate({ locale: localeToLoad, messages }); AppStorage.local.setItem(SELECTED_LANGUAGE_CODE_KEY, localeToLoad); } export async function initializeLocalization(): Promise { try { await loadCatalog(detectLocale()); } catch (e) { await loadCatalog(DEFAULT_LOCALE); } } export { i18n };