mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Add i18n support
This commit is contained in:
16
server/i18n.ts
Normal file
16
server/i18n.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { signal } from "@preact/signals";
|
||||
|
||||
export type I18NMap = { [x: string]: string | I18NMap };
|
||||
|
||||
export const i18n_map = signal<I18NMap>({});
|
||||
const NOT_FOUND = "__NOT_FOUND__";
|
||||
|
||||
export default function t(key: string) {
|
||||
const keys = key.split(".");
|
||||
let map: string | I18NMap = i18n_map.value;
|
||||
for (const k of keys) {
|
||||
if (typeof map === "string") return NOT_FOUND;
|
||||
else map = map[k];
|
||||
}
|
||||
return typeof map === "string" ? map : NOT_FOUND;
|
||||
}
|
||||
Reference in New Issue
Block a user