mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 15:22:52 +01:00
feat: i18n, page title
(cherry picked from commit 0d9fc72bee009c591400055725680a6a0f5a9c83)
This commit is contained in:
30
src/i18n/translation.ts
Normal file
30
src/i18n/translation.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {en} from "./languages/en.ts";
|
||||
import {zh_TW} from "./languages/zh_TW.ts";
|
||||
import {zh_CN} from "./languages/zh_CN.ts";
|
||||
import type I18nKey from "./i18nKey.ts";
|
||||
import {getConfig} from "../utils/config-utils.ts";
|
||||
|
||||
export type Translation = {
|
||||
[K in I18nKey]: string;
|
||||
}
|
||||
|
||||
const defaultTranslation = en;
|
||||
|
||||
const map: { [key: string]: Translation } = {
|
||||
"en": en,
|
||||
"en_us": en,
|
||||
"en_gb": en,
|
||||
"en_au": en,
|
||||
"zh_cn": zh_CN,
|
||||
"zh_tw": zh_TW,
|
||||
}
|
||||
|
||||
export function getTranslation(lang: string): Translation {
|
||||
lang = lang.toLowerCase();
|
||||
return map[lang] || defaultTranslation;
|
||||
}
|
||||
|
||||
export function i18n(key: I18nKey): string {
|
||||
const lang = getConfig().lang || "en";
|
||||
return getTranslation(lang)[key];
|
||||
}
|
||||
Reference in New Issue
Block a user