国际化

国际化开发指南

一. 关键术语

术语说明
语言包包含键值对翻译的 JSON 文件
语言代码遵循 BCP 47 标准(如 zh-CN
文本域(Domain)按模块划分翻译作用域

二. 如何支持国际化

app.i18n 实例

1import { Plugin } from '@tachybase/client';
2
3class PluginDemoClient extends Plugin {
4  async load() {
5    // i18n 实例
6    this.app.i18n;
7    this.app.i18n.t('hello');
8    await this.app.i18n.changeLanguage('zh-CN');
9  }
10}

详细说明请参考 I18next API 文档

React hook 方法

1import { useApp } from '@tachybase/client';
2import { useTranslation } from 'react-i18next';
3
4const { i18n } = useApp();
5const { t } = useTranslation();
6t('hello');

useTranslation() 的详细使用说明参考 react-i18next 文档

tval 方法

1const schema = {
2  type: 'string',
3  title: '{{t("I'm fine", { ns: "core" })}}',
4  'x-component': 'FormItem',
5  'x-component': 'Input',
6};

或者

1import { tval } from '@tachybase/client';
2
3const schema = {
4  type: 'string',
5  title: tval("I'm fine", { ns: 'core', ...others }),
6  'x-component': 'FormItem',
7  'x-component': 'Input',
8};