Download the Solution Example here: LocalizationExample.zip
Software Version: 10.1
Summary
This solution example demonstrates how to switch the language of components using Localization options.
Technical Information
To set up multiple languages in your solution, go to Displays → Localization, click on the “Insert New…“ button and choose a name for your Localization. An empty Localization Table will be created. Fill each row with the original text and its translation, as shown in the figure below.
In the example above, there are three Localization options: Default, Português and Español. There are two ways to change your solution’s Localization. The first is by directly setting the client’s Localization property:
@Client.Localization = "Português";
The second is by calling method SetLocalization:
@Client.SetLocalization("Español");
Alternatively, if you want to return the Localization to Default, pass an empty string to the Localization property or the SetLocalization method.
To apply your Localization to simple textual components, double-click on them and insert the text you wish to translate like this:
Client.Locale("Your text here");
If your text exists in the Localization Table, it will be translated. In this solution example, you can verify that the Localization you choose in the Language ComboBox applies to TextBlocks, Buttons, Tag References, and even other Displays, such as the header and the help popups.
However, certain components are exceptions to this process. For instance, ComboBoxes and DataGrids need to be translated through the Display’s CodeBehind. To translate a DataGrid, you can store the Default column titles in a list, as in this example’s CodeBehind:
var employeeDataGridTitles = new List<string>(); var employeeDataGrid = CurrentDisplay.GetControl("EmployeeDataGrid") as TDataGrid; foreach(var column in employeeDataGrid.Columns) employeeDataGridTitles.Add(column.Title);
Then, update the DataGrid titles when a different Localization is selected:
for(int i = 0; i < employeeDataGridTitles.Count; i++) employeeDataGrid.Columns[i].Title = @Client.Locale(employeeDataGridTitles[i]);
A similar procedure can be used to translate ComboBoxes. In this example, we use a ComboBox to choose the position of a new employee. We want to localize the ComboBox, but keep the selected position in English when we add it to our table of employees. First, we set up a tag containing an array of position texts. Then, we localize each array entry and add it to the ComboBox:
@Tag.Positions[0].Value = "Electrician"; @Tag.Positions[1].Value = "Engineer"; @Tag.Positions[2].Value = "Human Resources"; @Tag.Positions[3].Value = "Software Developer"; @Tag.Positions[4].Value = "Administrator"; positionComboBox = CurrentDisplay.GetControl("PositionComboBox") as TComboBox; for(int i = 0; i < @Tag.Positions.ArraySize; i++) positionComboBox.Items.Add(@Client.Locale(@Tag.Positions[i].Value));
To localize the ComboBox again, it is possible to empty it and use the same loop as above. Then, to add the employee to the table with the position written in the Default language, in Datasets → Queries, we use the ComboBox’s selected index to access the Default text in Tag.Positions:
INSERT INTO Employees VALUES ( (SELECT COUNT(*) FROM Employees), -- ID equal to the number of rows 'Employee' || (SELECT COUNT(*) FROM Employees), -- Name as 'Employee' + number of rows '{Tag.Positions[Tag.PositionIndex].Value}' -- Position as an empty string );
Reference Information
→ See Displays and Visualization for more information.
→ See ComboBox From Table Example for a simple guide on how to populate DataGrids and ComboBoxes.
In this section: