Creating Texts in Text Lists and Displaying Dynamically
A text list can have multiple languages defined in order to translate the default texts. It is then possible to change the language of the visualization via an input configuration.
Texts which are defined together in a text list can be displayed sequentially in a visualization element. This kind of dynamic text output is based on a changing ID in the Text index element property of the visualization element. Whenever the ID changes, the text output is refreshed to reflect the newly referenced text. The element which is intended for text output requires the name of the text list as the initial text reference in the Text list property and a variable for the ID of the text list entry in the property Text index. The variable value can then be set to a different ID in the application code.
The following step-by-step instructions describe how to dynamically output text within a rectangle element. However, it is also possible to output text in an Alarm element. The programmatic mechanics are the same.
Creating a text list
First, a text list with multiple entries and multiple languages must be created.
Requirement: A project with a visualization is open.
In the device tree, select an application and click the Project → Add Object command.
Select the Text list object and specify a name for the new object.
TextList_ANote: A text list can be located globally in the POU view or below an application in the device tree.
Click Add to exit the dialog.
The new object has been created and is displayed as an empty list in the editor.
In the text list, click in the Default column so that an input field opens. Specify a text.
Text for AThe default text is created. A 0 is automatically displayed in the ID column. The ID is used as a key in the table and the default text is used as the source text for translations.
In the ID column, specify an ID of your choice for the new text.
AA text list entry is defined.
In the Default column, double-click in the last blank row and define additional text list entries.
Add the languages
de,en, anditto the text list.For more information, see the help for the Add Language command.
Translate the default texts.
Now the text list
TextList_Acontains multiple entries with unique IDs, the desired default texts, and the respective translations in German, English, and Italian.
The text list can now be used to dynamically output text or to change the language.
Dynamically displaying a text
If the text list exists, then the variables which are required for output and changing the language have to be declared in the application code. Moreover, a visualization element has to be initialized for the output. After that, the variables and the visualization can be programmed as needed.
Requirement: A project is open and a text list exists.
In your application code, program the variable
PLC_PRG.sTextIdof typeSTRING.Add a new visualization to your application.
An empty visualization is shown in the visualization editor.
Drag a Rectangle visualization element to the visualization. This rectangle is used for text output.
In the Dynamic Texts property category, configure the properties for the new rectangle.
When specifying the values, pay special attention to use single straight quotation marks. Both the text list and the text index are expected to be string literals. Alternatively, you could also assign an IEC variable of type
STRING.When you double-click in one of the input fields (Value column), you will get help. For the text list, a list box provides the text lists defined in the project. For the text index, the Input Assistant opens for selecting project variables.
Property: Text list:
'TextList_A'Property: Text index: variable
PLC_PRG.sTextId
Add 3 more rectangles to the visualization. These rectangles are used for language switching.
Configure the first one as follows:
Property: Text: de
Property: Input configuration >
OnMouseDown> Change Language >deConfigure the second one as follows:
Property: Text:
enProperty: Input configuration >
OnMouseDown> Change Language >enConfigure the third one as follows:
Property: Text :
itProperty: Input configuration >
OnMouseDown> Change Language >it
Build the application, download it to the controller, and start it.
As a visualization user, you can change the language by clicking on a language rectangle.
In online mode, you can monitor the
PLC_PRGprogram and force the variablesTextIdwith the values'A','B', or'C.For more information, see the following: Forcing and Writing of Variables
