i18n
Reactant translation implemented with reflections, which allow you to get the translated text with a neat function call.
Define your translation string table
The I18nTable
is a class which act like a schema, the table class must:
- Annotated with
@I18n()
- Implemented I18nTable
- open concrete class (i.e. open non-abstract)
- No constructor parameters
To define your translation string, you can declare an open
function with the parameters you need and return the default translation inside the I18nTable
.
Edit translation
Generate translation file
We provided a command tools for you to manage your translations file more easily.
To list all declared i18n table in the server, run the following command:
To generate the dummy translation file for further usage, run the following command:
Now you can go to plugins/Reactant/i18n/tables/<path_to_your_class>/en.json
to find your translation file.
The generated translation file contains the parameters name to hint you.
You can edit the text in the translation file and use $PARAMETER_NAME
to replace the text.
The missing translation field will be replaced with the default translation from the i18n table.
Use the translation string
Injectable
To get the translation string in component, you can inject the translation class directly.
Change server default language
You can change the server default language setting in plugins/Reactant/i18n/config.json
: