I18n

NocoBase plugins support multi-language internationalization (i18n) for both frontend and backend. Through a unified mechanism, you can easily implement multi-language content in plugins.

Multi-language File Management

Plugin multi-language files are uniformly stored in the src/locale directory. It's recommended to name them by language, for example:

|- /plugin-hello
  |- /src
    |- /locale
      |- en-US.json   # English language
      |- zh-CN.json   # Chinese language

Each language file exports a JSON object containing all translation entries for that language, for example:

// zh-CN.json
{
  "Hello": "你好",
  "World": "世界",
  "Enter your name": "请输入你的名字",
  "Your name is {{name}}": "你的名字是 {{name}}"
}
// en-US.json
{
  "Hello": "Hello",
  "World": "World",
  "Enter your name": "Enter your name",
  "Your name is {{name}}": "Your name is {{name}}"
}

When adding language files for the first time, you need to restart the application for them to take effect. You can verify that the translation entries have taken effect through the API:
http://localhost:13000/api/app:getLang?locale=zh-CN

ctx.i18n

ctx.t(text, options)

plugin.t()

useT()

tExpr(text)

useTranslation(ns)

withTranslation(ns)