From a81d1b11da0cf3f22071fd9962b3f4e49d37f134 Mon Sep 17 00:00:00 2001 From: Mara Date: Sun, 28 Jan 2024 15:50:11 +0100 Subject: [PATCH] feat: update i18next to load language files from locales --- src/i18n/i18next.ts | 64 ++++++++++++++++++++++-- src/i18n/locales/{zh.json => zh-CN.json} | 0 src/main.ts | 1 + tsconfig.json | 1 + 4 files changed, 62 insertions(+), 4 deletions(-) rename src/i18n/locales/{zh.json => zh-CN.json} (100%) diff --git a/src/i18n/i18next.ts b/src/i18n/i18next.ts index 69bcffe4..0034309d 100644 --- a/src/i18n/i18next.ts +++ b/src/i18n/i18next.ts @@ -1,11 +1,67 @@ -import {moment} from "obsidian"; +import { moment } from "obsidian"; -import * as en from "./locales/en.json"; -import * as fr from "./locales/fr.json"; +import af from "./locales/af.json"; +import ar from "./locales/ar.json"; +import ca from "./locales/ca.json"; +import cs from "./locales/cs.json"; +import da from "./locales/da.json"; +import de from "./locales/de.json"; +import el from "./locales/el.json"; +import en from "./locales/en.json"; +import es from "./locales/es.json"; +import fi from "./locales/fi.json"; +import fr from "./locales/fr.json"; +import he from "./locales/he.json"; +import it from "./locales/it.json"; +import ja from "./locales/ja.json"; +import ko from "./locales/ko.json"; +import nl from "./locales/nl.json"; +import no from "./locales/no.json"; +import pl from "./locales/pl.json"; +import pt from "./locales/pt.json"; +import ptBR from "./locales/pt-BR.json"; +import ro from "./locales/ro.json"; +import ru from "./locales/ru.json"; +import sr from "./locales/sr.json"; +import sv from "./locales/sv.json"; +import tr from "./locales/tr.json"; +import uk from "./locales/uk.json"; +import vi from "./locales/vi.json"; +import zhCN from "./locales/zh-CN.json"; +import zhTW from "./locales/zh-TW.json"; export const resources = { en: { translation: en }, fr: { translation: fr }, + af: { translation: af }, + ar: { translation: ar }, + ca: { translation: ca }, + cs: { translation: cs }, + da: { translation: da }, + de: { translation: de }, + el: { translation: el }, + es: { translation: es }, + fi: { translation: fi }, + he: { translation: he }, + it: { translation: it }, + ja: { translation: ja }, + ko: { translation: ko }, + nl: { translation: nl }, + no: { translation: no }, + pl: { translation: pl }, + pt: { translation: pt }, + "pt-BR": { translation: ptBR }, + ru: { translation: ru }, + ro: { translation: ro }, + sr: { translation: sr }, + sv: { translation: sv }, + tr: { translation: tr }, + uk: { translation: uk }, + vi: { translation: vi }, + "zh-TW": { translation: zhTW }, + "zh-CN": { translation: zhCN }, } as const; -export const translationLanguage = Object.keys(resources).find(i => i==moment.locale()) ? moment.locale() : "en"; +export const translationLanguage = Object.keys(resources).find(i => i.toLocaleLowerCase() == moment.locale()) ? moment.locale() : "en"; +console.log(`[i18n] Using ${translationLanguage} as translation language.`); +console.log(moment.locale()); \ No newline at end of file diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh-CN.json similarity index 100% rename from src/i18n/locales/zh.json rename to src/i18n/locales/zh-CN.json diff --git a/src/main.ts b/src/main.ts index f312ff4b..091341aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -188,6 +188,7 @@ export default class GithubPublisher extends Plugin { resources, returnNull: false, }); + console.log(`[i18n] Using ${translationLanguage} as translation language. LANG: ${i18next.language}, LOADED: ${i18next.languages.join(", ")}`); diff --git a/tsconfig.json b/tsconfig.json index 6009ade9..de084534 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,7 @@ "isolatedModules": true, "resolveJsonModule": true, "strict":true, + "allowSyntheticDefaultImports": true, "lib": [ "DOM", "ES5",