Multi-language Support
Multi-language Configuration
The extension supports multi-language configuration, you can create a <IANA Language Tags>.json
file in the ./locales/
folder, you can create a <IANA language tag>.json
file, which will be automatically associated with the corresponding language and called when appropriate.
{
"Enter": "确定",
"Cancel": "取消"
}
2
3
4
{
"Enter": "Enter",
"Cancel": "Cancel"
}
2
3
4
If you need to get all the language labels supported by the current extension, you can call the SYS_I18n.getAllSupportedLanguages() method, which will return an array of strings.
WARNING
Note that if your extension has two or more languages, it must include at least one of en
or zh-Hans
as a fallback language, otherwise you may encounter unexpected display errors.
Use of Multiple Languages within the Code
To use a multilingual system to display different text in different language environments, use the SYS_I18n.text() method.
SYS_I18n.text() method has a mandatory argument tag
, which corresponds to the key name in the multilingual file, and the key value matched by that key name is the final displayed text.
You can specify the namespace
parameter as the uuid
of other extensions to call the multilingual configuration of other extensions.
Currently, EasyEDA Professional only supports a few languages by default, while the extension API supports a lot of additional languages, you can use the language
parameter to adapt more languages for your extension, but you need to design your own logic and method to switch languages.
When translating a language, it is very likely that we will encounter a situation where we need to embed parameters into the text, because the syntax of each language is different and the position of the parameters in the text of the language may vary greatly, you can use a placeholder in the ${1}
format to indicate the parameters that need to be embedded and pass the parameters into the arg
of the SYS_I18n.text() method within arg
, so that when the specified text is displayed, the corresponding argument will be embedded in the text at the specified location.
TIP
Language priority: current display language > system default language > the first language in the dataset that contains the text tag > text label (tag)
In addition to the above steps, you may need to know other SYS_I18n APIs to work more freely with multilingual content.