🛫 Internationalization API
As our community gets bigger and bigger, language becomes a barrier for users and players from different countries to
communicate. To change this, we made I18nAPI
and encourage plugin creators use it.
Load translation data
i18n.load(path, defaultLocaleName, defaultLangData)
- Params:
- path:
String
The file1/directory2 where the translation data is located - defaultLocaleName:
String
default locale name, in the form ofzh_CN
oren
(this parameter will be used if the target language is not provided for the translation ofi18n.tr
ori18n.get
)
If an empty string is passed in, the default follows the system language - defaultLangData:
Object
This parameter will be used to complete or create translation files in the form ofJavaScript 1 2 3 4 5 6 7 8 9
{ localeName: { "src": "translation" }, en_CN: { "a.b.c.d.114514": "1919810", "src": "source" } }
- path:
- Throw:
- Invalid parameter
json
{
"localeName": {
"src": "translation"
},
"zh_CN": {
"a.b.c.d.114514": "1919810",
"src": "源"
}
}
Text Only | |
---|---|
1 2 3 |
|
Each file inside should be similar to:
json
{
"a.c.b.d": "translation",
"use": {
"nested": {
"src": "translation"
},
"114514": {
"1919810": "heng heng aaaaaaaaaaaaaaaaaaaaaaaaa",
"a": "此处的ID为use.nested.114514.a",
"b": "The ID of this will be use.nested.114514.b"
}
}
}
Get the translation of the text in the specified language
i18n.get(key[,localeName])
- Params:
- key:
String
Text or ID - localeName:
String
(Optional)
Target language, default is thedefaultLocaleName
passed in wheni18n.load
.
- key:
- Return value:
String
translation (if no translation is found after multiple fallbacks, thenkey
is returned) - Throw:
- Invalid parameter
Translate and format the text using the specified language
i18n.trl(localeName, key, ...)
- Parameters:
- localeName:
String
Target language - key:
String
Text or ID - ... :
Any
Format arguments
- localeName:
- Return value:
String
translated and formatted text - Note: Formatting should follow syntax
- Throw:
- Invalid parameter
Translate and format the text using the default language
i18n.tr(key, ...)
- Parameters:
- key:
String
Text or ID - ... :
Any
Format arguments
- key:
- Return value:
String
translated and formatted text - Note: Formatting should follow syntax
- Throw:
- Invalid parameter
Full sample
JavaScript | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|