logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Globals

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.sql
Next Pagectx.view

#ctx.t()

i18n helper for translating strings in RunJS, based on the current context language. Suitable for inline text such as buttons, titles, and hints.

#Type definition

t(key: string, options?: Record<string, any>): string

#Parameters

ParameterTypeDescription
keystringTranslation key or template with placeholders (e.g. Hello {{name}}, {{count}} rows)
optionsobjectOptional. Interpolation variables (e.g. { name: 'Alice', count: 5 }) or i18n options (defaultValue, ns)

#Return value

  • Returns translated string. If no translation exists and no defaultValue is provided, it may return the key itself or the interpolated string.

#Notes

  • i18next-style interpolation is supported: use {{var}} in the key and pass variables in options.
  • Language is determined by current context (user language, app locale).
  • When the localization plugin is enabled, ctx.t strings are extracted for centralized translation management.

#Examples

#Simple keys

ctx.t('Submit');
ctx.t('No data');

#With interpolation

const text = ctx.t('Hello {{name}}', { name: ctx.user?.nickname || 'Guest' });
ctx.render(`<div>${text}</div>`);
ctx.message.success(ctx.t('Processed {{count}} rows', { count: rows.length }));

#Dynamic time text

if (minutes < 60) return ctx.t('{{count}} minutes ago', { count: minutes });
if (hours < 24) return ctx.t('{{count}} hours ago', { count: hours });

#Namespaces (ns)

When translation resources are split by namespace, use ns to specify which namespace to search:

// Read from a specific namespace
ctx.t('Submit', { ns: 'myModule' });

// Search multiple namespaces in order (myModule, then common)
ctx.t('Save', { ns: ['myModule', 'common'] });

// Interpolation with namespace
ctx.t('Hello {{name}}', { name: 'Guest', ns: 'myModule' });