logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.getVar()
Next Pagectx.importAsync()

#ctx.i18n

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.

#Scenarios

All RunJS execution environments can use ctx.i18n (e.g., JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage Rules, etc.).

#Type Definition

interface i18n: {
  language: string;
  changeLanguage(lng: string): Promise<any>;
}

#Common Properties

PropertyTypeDescription
languagestringThe currently active language code (e.g., en-US, zh-CN)

#Common Methods

#changeLanguage(lng)

Switches the current language.

ParameterTypeDescription
lngstringTarget language code (e.g., 'en-US', 'zh-CN')

Returns: Promise<any>, resolves after the language switch is complete.

#Examples

#Reading the current language

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'));
}

#Switching languages

// Switch to English
await ctx.i18n.changeLanguage('en-US');

// Switch to Chinese
await ctx.i18n.changeLanguage('zh-CN');

#Language switch button

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>,
);

#Notes

  • Translation text: Use ctx.t() consistently; do not use ctx.i18n.t.

#Related

  • ctx.t(): Translate text, use this method consistently.