feat: partial locale type

This commit is contained in:
Yidadaa
2023-05-19 00:59:04 +08:00
parent de775511d0
commit 50cfbaaab5
5 changed files with 27 additions and 4 deletions

View File

@@ -241,6 +241,11 @@ const cn = {
},
};
export type LocaleType = typeof cn;
type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;
export type LocaleType = DeepPartial<typeof cn>;
export default cn;

View File

@@ -11,6 +11,7 @@ import VI from "./vi";
import RU from "./ru";
import CS from "./cs";
import KO from "./ko";
import { merge } from "../utils/merge";
export type { LocaleType } from "./cn";
@@ -80,7 +81,8 @@ export function changeLang(lang: Lang) {
location.reload();
}
export default {
const fallbackLang = EN;
const targetLang = {
en: EN,
cn: CN,
tw: TW,
@@ -95,3 +97,8 @@ export default {
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;