# ctx.i18n

The i18n instance for the current context; used to read or change the language. **Use [ctx.t()](./t.md) for all translated text**; do not use `ctx.i18n.t`.

## Use Cases

Available in all RunJS environments (JSBlock, JSField, JSItem, JSColumn, event flow, linkage, etc.).

## Type

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

## Common Properties

| Property | Type | Description |
|----------|------|-------------|
| `language` | `string` | Current language code (e.g. `zh-CN`, `en-US`) |

## Common Methods

### changeLanguage(lng)

Change the current language.

| Parameter | Type | Description |
|-----------|------|-------------|
| `lng` | `string` | Target language code (e.g. `en-US`, `zh-CN`) |

**Returns**: `Promise<any>`, resolves when the language has been changed.

## Examples

### Read current language

```ts
const lang = ctx.i18n.language;
if (lang.startsWith('zh')) {
  ctx.render(ctx.t('Chinese UI'));
} else {
  ctx.render(ctx.t('English UI'));
}
```

### Change language

```ts
await ctx.i18n.changeLanguage('en-US');

await ctx.i18n.changeLanguage('zh-CN');
```

### Language switch button

```ts
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

- **Translated text**: Use `ctx.t()` only; do not use `ctx.i18n.t`.

## Related

- [ctx.t()](./t.md): translation; use this for all copy
