Эта страница является
переводом страницы
SwitchLanguage. Перевод выполнен на 100%.
Support of several languages in i3 pro
The example shows creation of a user interface for i3 pro app in several languages.To realize it, it is required to use Script editor built-in iRidium Studio.
The documentation was updated on 20.8.2021
1 Open iRidium Studio and create a panel project.
2 Add several graphic items to the interface and fill in their Text field.а
3 Create a new script in Script editor and add the given code to it:
var button_translate = IR.GetItem("Page 1").GetItem("Item 1");
// dictionary:
var dictionary = {
// ENG to RU
"Text 1": "Текст 1",
"Text 2" : "Текст 2",
"Translation" : "Перевести",
// RU to ENG
"Перевести": "Translation",
"Текст 1": "Text 1",
"Текст 2": "Text 2"
}
function find_dictionary_value_by_key(key) {
var value = dictionary[key];
if(value)
return value;
return key;
}
function change_text_item_by_dictionary(page) {
if(page) {
IR.Log(page.ItemsCount);
for(var j = 0; j < page.ItemsCount; j++) {
var item = page.GetItem(j);
item.Text = find_dictionary_value_by_key(item.Text);
}
}
}
function translate_all_pages_and_popups() {
for(var i = 0; i < IR.PagesCount; i++)
change_text_item_by_dictionary(IR.GetPage(i));
for(var i = 0; i < IR.PopupsCount; i++)
change_text_item_by_dictionary(IR.GetPopup(i));
}
IR.AddListener(IR.EVENT_ITEM_RELEASE, button_translate, translate_all_pages_and_popups);
4 Replace the words in the script with those that you want to translate in the graphical interface.
The script goes through all items on a page, finds corresponding text on the dictionary and replaces it with the chosen translation.
The translation is done on all pages and popups of a project at once.
5 Replace the link in the first string with a link to an item, by pressing which text on graphic items will be translated. In the last line of the code, you subscribe to an event that happens when the given button is pressed.
6 Start i3 pro Emulator. When the Translation button is changed, the language of the project changes from English into Russian.