Selecting a Language
Selecting a language for your Perspective session is done through session properties, specifically the locale session property. By default, this property is set to the language tag "en-US" for English USA. Once you set up a additional languages in the Translation system, you can set your locale session property to different values depending on what language you want to see on your screen.
Switching Languages within a Session
In this example, we'll set up a dropdown list from which the user can choose a language. For this example, we've already set up a Spanish Translation List. We've added a key "Hot" and its Spanish translation, "Caliente".
Now we'll setup a view where the user can choose between English and Spanish.
- Create a new view and put a Label component and a Dropdown component on the view.
- Set the text property of the label to "Hot."
- In the Project Browser, click on Perspective. The Session properties are displayed. Update the locale session property to "es-US" (the language tag for Spanish USA).
This results in anything in your session that contains the word "Hot" to be translated to its Spanish translation.
Similarly, if you set the locale session property back to "en-US", Ignition will translate your session text back to English.
- Next we'll set up the Dropdown component with two options configured as shown below where the Spanish option is tied to the "es-US" language tag and the English option is tied to the "en-US" language tag.
- Next we'll bi-directionally bind the Dropdown's Value property to the Locale session property. In the Property editor, click the Binding icon for the value property.
- On the Edit Binding screen, select the Property Binding type.
- Next click the Property Details icon. Scroll to the session.props.locale and click OK.
- Select the Bidirectional option. Click OK to save the binding.
- Put the Designer into Preview mode and test the Dropdown component. Since your Dropdown component now drives your Locale session property, you will be able to see your Label value go from its Spanish to English translation as you change the language selection.