forked from XiaoMo/ChatGPT-Next-Web
feat: partial locale type
This commit is contained in:
parent
de775511d0
commit
50cfbaaab5
@ -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;
|
export default cn;
|
||||||
|
@ -11,6 +11,7 @@ import VI from "./vi";
|
|||||||
import RU from "./ru";
|
import RU from "./ru";
|
||||||
import CS from "./cs";
|
import CS from "./cs";
|
||||||
import KO from "./ko";
|
import KO from "./ko";
|
||||||
|
import { merge } from "../utils/merge";
|
||||||
|
|
||||||
export type { LocaleType } from "./cn";
|
export type { LocaleType } from "./cn";
|
||||||
|
|
||||||
@ -80,7 +81,8 @@ export function changeLang(lang: Lang) {
|
|||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
const fallbackLang = EN;
|
||||||
|
const targetLang = {
|
||||||
en: EN,
|
en: EN,
|
||||||
cn: CN,
|
cn: CN,
|
||||||
tw: TW,
|
tw: TW,
|
||||||
@ -95,3 +97,8 @@ export default {
|
|||||||
cs: CS,
|
cs: CS,
|
||||||
ko: KO,
|
ko: KO,
|
||||||
}[getLang()] as typeof CN;
|
}[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;
|
||||||
|
@ -15,7 +15,7 @@ export const BUILTIN_MASK_STORE = {
|
|||||||
return this.masks[id] as Mask | undefined;
|
return this.masks[id] as Mask | undefined;
|
||||||
},
|
},
|
||||||
add(m: BuiltinMask) {
|
add(m: BuiltinMask) {
|
||||||
const mask = { ...m, id: this.buildinId++ };
|
const mask = { ...m, id: this.buildinId++, builtin: true };
|
||||||
this.masks[mask.id] = mask;
|
this.masks[mask.id] = mask;
|
||||||
return mask;
|
return mask;
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
import { type Mask } from "../store/mask";
|
import { type Mask } from "../store/mask";
|
||||||
|
|
||||||
export type BuiltinMask = Omit<Mask, "id">;
|
export type BuiltinMask = Omit<Mask, "id"> & {
|
||||||
|
builtin: true;
|
||||||
|
};
|
||||||
|
9
app/utils/merge.ts
Normal file
9
app/utils/merge.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export function merge(target: any, source: any) {
|
||||||
|
Object.keys(source).forEach(function (key) {
|
||||||
|
if (source[key] && typeof source[key] === "object") {
|
||||||
|
merge((target[key] = target[key] || {}), source[key]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
target[key] = source[key];
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user