docs/docs/en/runjs/context/i18n.md
The i18n instance of the current context, used for reading or switching languages. Use ctx.t() for translating text; do not use ctx.i18n.t.
All RunJS execution environments can use ctx.i18n (e.g., JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage Rules, etc.).
interface i18n: {
language: string;
changeLanguage(lng: string): Promise<any>;
}
| Property | Type | Description |
|---|---|---|
language | string | The currently active language code (e.g., en-US, zh-CN) |
Switches the current language.
| Parameter | Type | Description |
|---|---|---|
lng | string | Target language code (e.g., 'en-US', 'zh-CN') |
Returns: Promise<any>, resolves after the language switch is complete.
const lang = ctx.i18n.language;
// 'en-US' | 'zh-CN' | ...
if (lang.startsWith('zh')) {
ctx.render(ctx.t('Chinese UI'));
} else {
ctx.render(ctx.t('English UI'));
}
// Switch to English
await ctx.i18n.changeLanguage('en-US');
// Switch to Chinese
await ctx.i18n.changeLanguage('zh-CN');
const { Button } = ctx.libs.antd;
const isZh = ctx.i18n.language.startsWith('zh');
ctx.render(
<Button onClick={async () => {
await ctx.i18n.changeLanguage(isZh ? 'en-US' : 'zh-CN');
}}>
{ctx.t(isZh ? 'Switch to English' : 'Switch to Chinese')}
</Button>,
);
ctx.t() consistently; do not use ctx.i18n.t.