-
Notifications
You must be signed in to change notification settings - Fork 9
Internationalization
You can choose to either allow the user to translate strings manually via configurations, or implement translation schemes, similar to the ones used internally.
It's required to override the value of translationMap to a string-map map like this:
function onLoad() {
translationMap = {
'messages.hello': {
en: 'Hello in English',
it: 'Ciao in italiano',
de: 'Hallo auf Deutsch',
ru: 'Здравствуйте по-русски',
zhcn: '中文你好'
},
'other': {
...
}
}
}As you can see, the values of translationMap are other maps built by language tag on the left and translation on the right. Current supported languages are English (en), Italian (it), German (de), Russian (ru) and simplified Chinese (zhcn).
NOTE! If a sub-map misses of a language tag, it will take the English value.
Then, you can access translations anywhere by using translate(key):
print(translate('messages.hello'));Chorus has a built-in function to translate text via reverso.net.
You can dynamically translate a string by calling translateFromWeb(from, to, text). Example:
translateFromWeb('ita', 'eng', 'Ciao a tutti, grazie per aver usato Chorus!');Result:
Hello everyone, thank you for using Chorus!
NOTE! It's suggested to fetch translations asynchronously via runAsync(action).
Note that this feature should not be overused and that Reverso's script may change at any time.