diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 0dc5d354..187a3c7a 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -284,7 +284,8 @@ type DeepPartial = T extends object [P in keyof T]?: DeepPartial; } : T; -export type LocaleType = DeepPartial; -export type RequiredLocaleType = typeof cn; + +export type LocaleType = typeof cn; +export type PartialLocaleType = DeepPartial; export default cn; diff --git a/app/locales/cs.ts b/app/locales/cs.ts index 734db37f..50082835 100644 --- a/app/locales/cs.ts +++ b/app/locales/cs.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const cs: LocaleType = { +const cs: PartialLocaleType = { WIP: "V přípravě...", Error: { Unauthorized: diff --git a/app/locales/de.ts b/app/locales/de.ts index 7b0ca5cc..e9b8895f 100644 --- a/app/locales/de.ts +++ b/app/locales/de.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const de: LocaleType = { +const de: PartialLocaleType = { WIP: "In Bearbeitung...", Error: { Unauthorized: diff --git a/app/locales/en.ts b/app/locales/en.ts index 6d7174dc..25b7f397 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import { RequiredLocaleType } from "./index"; +import { LocaleType } from "./index"; -const en: RequiredLocaleType = { +const en: LocaleType = { WIP: "Coming Soon...", Error: { Unauthorized: diff --git a/app/locales/es.ts b/app/locales/es.ts index 15f731cb..568ce30b 100644 --- a/app/locales/es.ts +++ b/app/locales/es.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const es: LocaleType = { +const es: PartialLocaleType = { WIP: "En construcción...", Error: { Unauthorized: diff --git a/app/locales/fr.ts b/app/locales/fr.ts index 046cebe6..a28c4102 100644 --- a/app/locales/fr.ts +++ b/app/locales/fr.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const fr: LocaleType = { +const fr: PartialLocaleType = { WIP: "Prochainement...", Error: { Unauthorized: diff --git a/app/locales/index.ts b/app/locales/index.ts index 4f7e145d..38d54770 100644 --- a/app/locales/index.ts +++ b/app/locales/index.ts @@ -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"; +import type { LocaleType } from "./cn"; +export type { LocaleType, PartialLocaleType } 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]; +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 = { 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; diff --git a/app/locales/it.ts b/app/locales/it.ts index 0d87588f..8e54664a 100644 --- a/app/locales/it.ts +++ b/app/locales/it.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const it: LocaleType = { +const it: PartialLocaleType = { WIP: "Work in progress...", Error: { Unauthorized: diff --git a/app/locales/jp.ts b/app/locales/jp.ts index 7a899be0..3e2cadb3 100644 --- a/app/locales/jp.ts +++ b/app/locales/jp.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const jp: LocaleType = { +const jp: PartialLocaleType = { WIP: "この機能は開発中です", Error: { Unauthorized: diff --git a/app/locales/ko.ts b/app/locales/ko.ts index 12b8db28..fe87df21 100644 --- a/app/locales/ko.ts +++ b/app/locales/ko.ts @@ -1,8 +1,8 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const ko: LocaleType = { +const ko: PartialLocaleType = { WIP: "곧 출시 예정...", Error: { Unauthorized: "권한이 없습니다. 설정 페이지에서 액세스 코드를 입력하세요.", diff --git a/app/locales/no.ts b/app/locales/no.ts index de2f6dee..fde47988 100644 --- a/app/locales/no.ts +++ b/app/locales/no.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const no: LocaleType = { +const no: PartialLocaleType = { WIP: "Arbeid pågår ...", Error: { Unauthorized: "Du har ikke tilgang. Vennlig oppgi tildelt adgangskode.", diff --git a/app/locales/ru.ts b/app/locales/ru.ts index 3993ea43..03f34948 100644 --- a/app/locales/ru.ts +++ b/app/locales/ru.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const ru: LocaleType = { +const ru: PartialLocaleType = { WIP: "Скоро...", Error: { Unauthorized: diff --git a/app/locales/tr.ts b/app/locales/tr.ts index e26091fe..9294df91 100644 --- a/app/locales/tr.ts +++ b/app/locales/tr.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const tr: LocaleType = { +const tr: PartialLocaleType = { WIP: "Çalışma devam ediyor...", Error: { Unauthorized: diff --git a/app/locales/tw.ts b/app/locales/tw.ts index 025e5e61..ee1e3676 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const tw: LocaleType = { +const tw: PartialLocaleType = { WIP: "該功能仍在開發中……", Error: { Unauthorized: "目前您的狀態是未授權,請前往設定頁面輸入授權碼。", diff --git a/app/locales/vi.ts b/app/locales/vi.ts index 78eeaf40..26e7f14f 100644 --- a/app/locales/vi.ts +++ b/app/locales/vi.ts @@ -1,7 +1,7 @@ import { SubmitKey } from "../store/config"; -import type { LocaleType } from "./index"; +import type { PartialLocaleType } from "./index"; -const vi: LocaleType = { +const vi: PartialLocaleType = { WIP: "Sắp ra mắt...", Error: { Unauthorized: