Internationalization

Internationalization development guide

I. Key Terms

TermDescription
Language PackJSON file containing key-value translations
Language CodeFollows BCP 47 standard (e.g., zh-CN)
Text DomainTranslation scope divided by module

II. How to Support Internationalization

app.i18n Instance

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

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

For detailed documentation, refer to I18next API Documentation

React Hook Method

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

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

For detailed usage of useTranslation(), refer to react-i18next documentation

tval Method

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

Or

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

const schema = {
  type: 'string',
  title: tval("I'm fine", { ns: 'core', ...others }),
  'x-component': 'FormItem',
  'x-component': 'Input',
};
Total visits  times     Total visitors  times     Total reading  times.   Powered by Tego Team