61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
![]() |
export type GenericI18n_noJsx<MessageKey extends string, LanguageTag extends string> = {
|
||
|
/**
|
||
|
* e.g: "en", "fr", "zh-CN"
|
||
|
*
|
||
|
* The current language
|
||
|
*/
|
||
|
currentLanguageTag: LanguageTag;
|
||
|
/**
|
||
|
* Redirect to this url to change the language.
|
||
|
* After reload currentLanguageTag === newLanguageTag
|
||
|
*/
|
||
|
getChangeLocaleUrl: (newLanguageTag: string /*LanguageTag*/) => string;
|
||
|
/**
|
||
|
* e.g. "en" => "English", "fr" => "Français", ...
|
||
|
*
|
||
|
* Used to render a select that enable user to switch language.
|
||
|
* ex: https://user-images.githubusercontent.com/6702424/186044799-38801eec-4e89-483b-81dd-8e9233e8c0eb.png
|
||
|
* */
|
||
|
labelBySupportedLanguageTag: Record<string, string>;
|
||
|
/**
|
||
|
*
|
||
|
* Examples assuming currentLanguageTag === "en"
|
||
|
* {
|
||
|
* en: {
|
||
|
* "access-denied": "Access denied",
|
||
|
* "impersonateTitleHtml": "<strong>{0}</strong> Impersonate User",
|
||
|
* "bar": "Bar {0}"
|
||
|
* }
|
||
|
* }
|
||
|
*
|
||
|
* msgStr("access-denied") === "Access denied"
|
||
|
* msgStr("not-a-message-key") Throws an error
|
||
|
* msgStr("impersonateTitleHtml", "Foo") === "<strong>Foo</strong> Impersonate User"
|
||
|
* msgStr("${bar}", "<strong>c</strong>") === "Bar <strong>XXX</strong>"
|
||
|
* The html in the arg is partially escaped for security reasons, it might come from an untrusted source, it's not safe to render it as html.
|
||
|
*/
|
||
|
msgStr: (key: MessageKey, ...args: (string | undefined)[]) => string;
|
||
|
/**
|
||
|
* This is meant to be used when the key argument is variable, something that might have been configured by the user
|
||
|
* in the Keycloak admin for example.
|
||
|
*
|
||
|
* Examples assuming currentLanguageTag === "en"
|
||
|
* {
|
||
|
* en: {
|
||
|
* "access-denied": "Access denied",
|
||
|
* }
|
||
|
* }
|
||
|
*
|
||
|
* advancedMsgStr("${access-denied}") === advancedMsgStr("access-denied") === msgStr("access-denied") === "Access denied"
|
||
|
* advancedMsgStr("${not-a-message-key}") === advancedMsgStr("not-a-message-key") === "not-a-message-key"
|
||
|
*/
|
||
|
advancedMsgStr: (key: string, ...args: (string | undefined)[]) => string;
|
||
|
|
||
|
/**
|
||
|
* Initially the messages are in english (fallback language).
|
||
|
* The translations in the current language are being fetched dynamically.
|
||
|
* This property is true while the translations are being fetched.
|
||
|
*/
|
||
|
isFetchingTranslations: boolean;
|
||
|
};
|