diff options
author | crupest <crupest@outlook.com> | 2023-09-21 23:49:12 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-09-21 23:49:12 +0800 |
commit | d477c7270c90b190ed82b13f48f39a05d83503d2 (patch) | |
tree | 572f74b2adc75247b9d1c9a8965e3de2559d4160 /FrontEnd/src/i18n/text.ts | |
parent | a8a8385cd959e4d9d57b8a35381d2851049c07ff (diff) | |
download | timeline-d477c7270c90b190ed82b13f48f39a05d83503d2.tar.gz timeline-d477c7270c90b190ed82b13f48f39a05d83503d2.tar.bz2 timeline-d477c7270c90b190ed82b13f48f39a05d83503d2.zip |
Fix #1394.
Diffstat (limited to 'FrontEnd/src/i18n/text.ts')
-rw-r--r-- | FrontEnd/src/i18n/text.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/FrontEnd/src/i18n/text.ts b/FrontEnd/src/i18n/text.ts new file mode 100644 index 00000000..f8f7e7e6 --- /dev/null +++ b/FrontEnd/src/i18n/text.ts @@ -0,0 +1,35 @@ +import i18n from "i18next"; +import { useTranslation } from "react-i18next"; + +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 { + 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; +} + +export function createC(t: T): C { + return ((text) => convertI18nText(text, t)) as C; +} + +export const c = createC(i18n.t); + +export function useC(ns?: string): C { + const { t } = useTranslation(ns); + return createC(t); +} + |