国际化

国际化开发指南

一. 关键术语

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

二. 如何支持国际化

app.i18n 实例

import { Plugin } from '@tachybase/client';

class PluginDemoClient extends Plugin {
  async load() {
    // i18n 实例
    this.app.i18n;
    this.app.i18n.t('hello');
    await this.app.i18n.changeLanguage('zh-CN');
  }
}

详细说明请参考 I18next API 文档

React hook 方法

import { useApp } from '@tachybase/client';
import { useTranslation } from 'react-i18next';

const { i18n } = useApp();
const { t } = useTranslation();
t('hello');

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

tval 方法

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

或者

import { tval } from '@tachybase/client';

const schema = {
  type: 'string',
  title: tval("I'm fine", { ns: 'core', ...others }),
  'x-component': 'FormItem',
  'x-component': 'Input',
};