|
@@ -1,57 +1,71 @@
|
|
|
-import CN from "./cn";
|
|
|
-import EN from "./en";
|
|
|
-import TW from "./tw";
|
|
|
-import FR from "./fr";
|
|
|
-import ES from "./es";
|
|
|
-import IT from "./it";
|
|
|
-import TR from "./tr";
|
|
|
-import JP from "./jp";
|
|
|
-import DE from "./de";
|
|
|
-import VI from "./vi";
|
|
|
-import RU from "./ru";
|
|
|
-import NO from "./no";
|
|
|
-import CS from "./cs";
|
|
|
-import KO from "./ko";
|
|
|
+import cn from "./cn";
|
|
|
+import en from "./en";
|
|
|
+import tw from "./tw";
|
|
|
+import fr from "./fr";
|
|
|
+import es from "./es";
|
|
|
+import it from "./it";
|
|
|
+import tr from "./tr";
|
|
|
+import jp from "./jp";
|
|
|
+import de from "./de";
|
|
|
+import vi from "./vi";
|
|
|
+import ru from "./ru";
|
|
|
+import no from "./no";
|
|
|
+import cs from "./cs";
|
|
|
+import ko from "./ko";
|
|
|
import { merge } from "../utils/merge";
|
|
|
|
|
|
-export type { LocaleType, RequiredLocaleType } from "./cn";
|
|
|
-
|
|
|
-export const AllLangs = [
|
|
|
- "en",
|
|
|
- "cn",
|
|
|
- "tw",
|
|
|
- "fr",
|
|
|
- "es",
|
|
|
- "it",
|
|
|
- "tr",
|
|
|
- "jp",
|
|
|
- "de",
|
|
|
- "vi",
|
|
|
- "ru",
|
|
|
- "cs",
|
|
|
- "ko",
|
|
|
-] as const;
|
|
|
-export type Lang = (typeof AllLangs)[number];
|
|
|
+import type { LocaleType } from "./cn";
|
|
|
+export type { LocaleType, PartialLocaleType } from "./cn";
|
|
|
+
|
|
|
+const ALL_LANGS = {
|
|
|
+ cn,
|
|
|
+ en,
|
|
|
+ tw,
|
|
|
+ jp,
|
|
|
+ ko,
|
|
|
+ fr,
|
|
|
+ es,
|
|
|
+ it,
|
|
|
+ tr,
|
|
|
+ de,
|
|
|
+ vi,
|
|
|
+ ru,
|
|
|
+ cs,
|
|
|
+ no,
|
|
|
+};
|
|
|
+
|
|
|
+export type Lang = keyof typeof ALL_LANGS;
|
|
|
+
|
|
|
+export const AllLangs = Object.keys(ALL_LANGS) as Lang[];
|
|
|
|
|
|
export const ALL_LANG_OPTIONS: Record<Lang, string> = {
|
|
|
cn: "简体中文",
|
|
|
en: "English",
|
|
|
tw: "繁體中文",
|
|
|
+ jp: "日本語",
|
|
|
+ ko: "한국어",
|
|
|
fr: "Français",
|
|
|
es: "Español",
|
|
|
it: "Italiano",
|
|
|
tr: "Türkçe",
|
|
|
- jp: "日本語",
|
|
|
de: "Deutsch",
|
|
|
vi: "Tiếng Việt",
|
|
|
ru: "Русский",
|
|
|
cs: "Čeština",
|
|
|
- ko: "한국어",
|
|
|
+ no: "Nynorsk",
|
|
|
};
|
|
|
|
|
|
const LANG_KEY = "lang";
|
|
|
const DEFAULT_LANG = "en";
|
|
|
|
|
|
+const fallbackLang = en;
|
|
|
+const targetLang = ALL_LANGS[getLang()] as LocaleType;
|
|
|
+
|
|
|
+// if target lang missing some fields, it will use fallback lang string
|
|
|
+merge(fallbackLang, targetLang);
|
|
|
+
|
|
|
+export default fallbackLang as LocaleType;
|
|
|
+
|
|
|
function getItem(key: string) {
|
|
|
try {
|
|
|
return localStorage.getItem(key);
|
|
@@ -96,26 +110,3 @@ export function changeLang(lang: Lang) {
|
|
|
setItem(LANG_KEY, lang);
|
|
|
location.reload();
|
|
|
}
|
|
|
-
|
|
|
-const fallbackLang = EN;
|
|
|
-const targetLang = {
|
|
|
- en: EN,
|
|
|
- cn: CN,
|
|
|
- tw: TW,
|
|
|
- fr: FR,
|
|
|
- es: ES,
|
|
|
- it: IT,
|
|
|
- tr: TR,
|
|
|
- jp: JP,
|
|
|
- de: DE,
|
|
|
- vi: VI,
|
|
|
- ru: RU,
|
|
|
- no: NO,
|
|
|
- cs: CS,
|
|
|
- ko: KO,
|
|
|
-}[getLang()] as typeof CN;
|
|
|
-
|
|
|
-// if target lang missing some fields, it will use fallback lang string
|
|
|
-merge(fallbackLang, targetLang);
|
|
|
-
|
|
|
-export default fallbackLang as typeof CN;
|