You are here: Start » Program Examples » HMI Translations
HMI Translations
Aim:
The application shows how to create a multi-language user interface.
Input:
A simple application showing smoothing and rotation of an image and an .xml file with the HMI labels for different languages.
Output:
The HMI with appropriate labels depending on the chosen language.
Hints:
To update labels after changing the language, you can use the HMI events. To load data from an .xml file, you need the XML tools.
Solution (FIS):
-
In the INITIALIZE section of the application, add a new Step macrofilter and name it LoadAvailableLanguages.
-
Add the Xml_LoadFile filter to load the .xml file with different versions of the HMI labels.
-
Add the Xml_SelectMultipleNodes to select all nodes of type "Language".
- Connect the inNode input to the Xml_LoadFile output.
- In the Properties section, set the inXPath input to /Translations/Language.
-
Add the Xml_GetStringAttribute to extract the "name" attribute.
-
Add a formula to select the first language as the default.
outSelection = 0
-
In the HMI window, add the Label control available in the Controls category and place it at the top right part of the HMI. Set the inText as Language:.
-
Next to the new label, add the ComboBox control available in the Controls category.
- Connect its inList input to the Xml_GetStringAttribute output from the LoadAvailableLanguages macrofilter.
- Connect the inSelection input to the output of the formula from the LoadAvailableLanguages macrofilter.
- Create a HMI event related to the SelectionChanged option and name it SelectedLanguageChanged.
-
Go to the SelectedLanguageChanged event. Load translation strings and send them to the HMI controls.
-
Add the Xml_LoadFile filter to load the .xml file with different versions of the HMI labels.
-
Add the StringToUpperCase filter and connect its input to the outTextoutput of the HMI ComboBox control.
-
Add a formula. Connect the output from the previous step to it and name it inLanguage.
outXPath = "/Translations/Language[@name=\"" + inLanguage + "\"]"
-
Add the Xml_SelectSingleNode filter. Connect its inNode input to the Xml_LoadFile filter output and the inXPath input to the formula outXPath output.
-
Add the Xml_SelectSingleNodeValue_AsString filter.
- Connect the inNode input to the Xml_SelectSingleNode output.
- Set its inXPath as SelectLanguage.
- Connect the outNodeValue output to the HMI Language label inText input.
-
Repeat the previous step 8 times for the data below:
- The inXPath input: OutputImage, the Output image: HMI label.
- The inXPath input: SmoothingLevel, the Smoothing level: HMI label.
- The inXPath input: Settings, the Settings HMI group box.
- The inXPath input: ImageSource, the Image source: HMI label.
- The inXPath input: UseColor, the Use Color Image HMI radio button.
- The inXPath input: UseMono, the Use Mono Image HMI radio button.
- The inXPath input: Effects, the Effects: HMI label.
- The inXPath input: RotationAngle, the Rotation angle: HMI label.
Macrofilter Main.
Macrofilter LoadAvailableLanguages.
Macrofilter SelectedLanguageChanged.
Further Readings
- HMI Controls - List of HMI controls.