template_0205
This commit is contained in:
33
RN_TEMPLATE/app/i18n/translate.ts
Normal file
33
RN_TEMPLATE/app/i18n/translate.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import i18n from "i18next"
|
||||
import type { TOptions } from "i18next"
|
||||
|
||||
import { TxKeyPath } from "."
|
||||
|
||||
/**
|
||||
* Translates text.
|
||||
* @param {TxKeyPath} key - The i18n key.
|
||||
* @param {TOptions} options - The i18n options.
|
||||
* @returns {string} - The translated text.
|
||||
* @example
|
||||
* Translations:
|
||||
*
|
||||
* ```en.ts
|
||||
* {
|
||||
* "hello": "Hello, {{name}}!"
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Usage:
|
||||
* ```ts
|
||||
* import { translate } from "./i18n"
|
||||
*
|
||||
* translate("hello", { name: "world" })
|
||||
* // => "Hello world!"
|
||||
* ```
|
||||
*/
|
||||
export function translate(key: TxKeyPath, options?: TOptions): string {
|
||||
if (i18n.isInitialized) {
|
||||
return i18n.t(key, options)
|
||||
}
|
||||
return key
|
||||
}
|
||||
Reference in New Issue
Block a user