aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/i18n.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-07-11 21:45:37 +0800
committercrupest <crupest@outlook.com>2023-07-11 21:45:37 +0800
commit34125b7c7a57b749cf8cbaf6bab8d3b186a52559 (patch)
treee5782d2988ca5b45b4973d1c1da8d296f5eb47ce /FrontEnd/src/i18n.ts
parent78f0934815a87573289c8e52af2666ea38c93251 (diff)
downloadtimeline-34125b7c7a57b749cf8cbaf6bab8d3b186a52559.tar.gz
timeline-34125b7c7a57b749cf8cbaf6bab8d3b186a52559.tar.bz2
timeline-34125b7c7a57b749cf8cbaf6bab8d3b186a52559.zip
...
Diffstat (limited to 'FrontEnd/src/i18n.ts')
-rw-r--r--FrontEnd/src/i18n.ts38
1 files changed, 38 insertions, 0 deletions
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);