ctx.t()
An i18n shortcut function used in RunJS to translate text based on the current context's language settings. It is suitable for internationalizing inline copy such as buttons, titles, and prompts.
Use Cases
ctx.t() can be used in all RunJS execution environments.
Type Definition
Parameters
Return Value
- Returns the translated string. If no translation exists for the key and no
defaultValueis provided, it may return the key itself or the interpolated string.
Namespace (ns)
The default namespace for the RunJS environment is runjs. When ns is not specified, ctx.t(key) will look up the key in the runjs namespace.
Examples
Simple Key
With Interpolation Variables
Dynamic Copy (e.g., Relative Time)
Specifying a Namespace
Notes
- Localization Plugin: To translate text, the Localization plugin must be activated. Missing translation keys will be automatically extracted to the localization management list for unified maintenance and translation.
- Supports i18next-style interpolation: Use
{{variableName}}in the key and pass the corresponding variable inoptionsto replace it. - The language is determined by the current context (e.g.,
ctx.i18n.language, user locale).
Related
- ctx.i18n: Read or switch languages

