diff options
author | crupest <crupest@outlook.com> | 2020-11-04 10:31:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-04 10:31:34 +0800 |
commit | 247f15813f914559846109c32f3a2c0e6d373fac (patch) | |
tree | edd36228f51bfdca2354cd5734028dd490a04350 /FrontEnd/src/app/common.ts | |
parent | a581cf642fa0ff06c27e3d3d95af02aec3abd87d (diff) | |
download | timeline-247f15813f914559846109c32f3a2c0e6d373fac.tar.gz timeline-247f15813f914559846109c32f3a2c0e6d373fac.tar.bz2 timeline-247f15813f914559846109c32f3a2c0e6d373fac.zip |
refactor: Refactor operation dialog.
Diffstat (limited to 'FrontEnd/src/app/common.ts')
-rw-r--r-- | FrontEnd/src/app/common.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/FrontEnd/src/app/common.ts b/FrontEnd/src/app/common.ts index 0a2d345f..681568bb 100644 --- a/FrontEnd/src/app/common.ts +++ b/FrontEnd/src/app/common.ts @@ -1,5 +1,6 @@ import React from "react"; import { Observable, Subject } from "rxjs"; +import { TFunction } from "i18next"; // This error is thrown when ui goes wrong with bad logic. // Such as a variable should not be null, but it does. @@ -42,3 +43,28 @@ export function useValueEventEmiiter<T>(): [ return [getter, trigger]; }, []); } + +export type I18nText = + | string + | { type: "custom"; value: string } + | { type: "i18n"; value: string }; + +export function convertI18nText(text: I18nText, t: TFunction): string; +export function convertI18nText( + text: I18nText | null | undefined, + t: TFunction +): string | null; +export function convertI18nText( + text: I18nText | null | undefined, + t: TFunction +): 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; + } +} |