Advanced Techniques - Multilingual data records
If you would like to show data records in more than one language in the portal,
e.g. German and English, you need the translation of the data record in each
language and the two-letter language code according to ISO 3166-1 - e.g.
"de" for German and "en"
for English. The method described below can of course be used for any number
of languages.
Create the application
Create a new application based on the application template
Basic application.
Select the data group in the application structure and create a new data field
via the
New menu / Data field.
Enter "Language code" as the title and select "Short text" as the data type. Click on "OK".
Create a
drop-down list
and enter "Language" as the title. Click on
Next.
Select the option
Special data sources
and the class "LanguageListProcessor". Click on "Next".
Select the data field "Language code"
to connect the drop-down list to it and then click on
Next and finally "Finish".
Now switch to the "All entries" page and open the
properties dialog of the view table
and add the data field "Language code" as a
table column.
Click on "OK" and
publish the application.
Then switch to the browser.
Create a German and English data record on the edit page.
As you can see, the view table on the "All entries" page
displays both data records with their language code. The function of the class
"LanguageListProcessor" is therefore to display
the language names in the drop-down list. It is much easier to select a language
than to select the right language code, as these are easily confused.
The class "LanguageListProcessor" stores the
corresponding language code in the data field. The language-dependent
display of data records can only be achieved with the saved language code.
To filter the data records dependent on the language, please reopen
the
properties dialog
of the view table.
Create a
filter that compares
the data field "Language code" with the system
value "Language".
Publish the application.
Refresh the application in the browser (F5 key). If your portal is
set to English, only the English data record will be shown in the table.
Now switch the portal to German.
The table now only shows the German data record.
Alongside the class "LanguageListProcessor"
that provides the entries for the drop-down list for the language, there are
also many more classes, which, for example, only list the languages
that you have in the
Regional settings of the Portal properties.
You can find more information about that
here.
The
Dynamic view element
can also be set up to display already saved language codes, like the drop-down list,
and then provides the language names instead of the codes.