From 34125b7c7a57b749cf8cbaf6bab8d3b186a52559 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 11 Jul 2023 21:45:37 +0800 Subject: ... --- FrontEnd/src/i18n.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'FrontEnd/src/i18n.ts') diff --git a/FrontEnd/src/i18n.ts b/FrontEnd/src/i18n.ts index 59b6f64a..3166ec3c 100644 --- a/FrontEnd/src/i18n.ts +++ b/FrontEnd/src/i18n.ts @@ -74,3 +74,41 @@ if (module.hot) { } export default i18n; + +export type I18nText = + | string + | { type: "text" | "custom"; value: string } + | { type: "i18n"; value: string }; + +type T = typeof i18n.t; + +export function convertI18nText(text: I18nText, t: T): string; +export function convertI18nText( + text: I18nText | null | undefined, + t: T, +): string | null; +export function convertI18nText( + text: I18nText | null | undefined, + t: T, +): string | null { + if (text == null) { + return null; + } else if (typeof text === "string") { + return t(text); + } else if (text.type === "i18n") { + return t(text.value); + } else { + return text.value; + } +} + +export interface C { + (text: I18nText): string; + (text: I18nText | null | undefined): string | null; +} + +export function createC(t: T): C { + return ((text) => convertI18nText(text, t)) as C; +} + +export const c = createC(i18n.t); -- cgit v1.2.3