Internationalization
Internationalization Files
In plugins, multi-language files for both frontend and backend are stored in the src/locale folder.
Add translation entries in the corresponding multi-language files (/src/locale/${lang}.ts). If it's the first time adding a multi-language file, you need to restart the application for it to take effect. You can check the app:getLang API to verify if translation entries have been added successfully.
Default URL: http://localhost:13000/api/app:getLang?locale=zh-CN
i18n Related APIs
- server
- app.i18n
- app.t(text, options)
- ctx.i18n
- ctx.t(text, options)
- plugin.t()
- client
- ctx.i18n
- ctx.t(text, options)
- plugin.t()
- useT()
- utils
- tExpr(text, options)
- react-i18next
- useTranslation(ns)
- withTranslation(ns)
Server
app.i18n server
app.i18n is the global i18n instance, generally used in CLI. For example, combined with inquirer for implementing command-line interactions.
app.t(text, options) server
ctx.i18n server
ctx.i18n is a cloneInstance of the global app.i18n, each request's ctx is completely independent and responds with multilingual information based on the client's language.
Client request parameters can be placed in the query string
Or in request headers (recommended)
Example
View http://localhost:13000/api/test-i18n?locale=zh-CN

