setTranslation
Creates a new variable that holds a translation Map based on a Translation part found inside the Online template this command is in.
As internal translation resources are a feature available only available in Online templates, this command cannot be used in Office legacy templates.
Attributes
var | ||
---|---|---|
Required | Value type | EL-evaluated |
Yes | String | No |
Defines the name of the variable that holds the translation Map. Depending on the |
value | ||
---|---|---|
Required | Value type | EL-evaluated |
No | DAP Part, String | Yes |
This attribute may be used to specify the translation resource to use. The resolved value is expected to either be a DAP Part representing a Translation part, or a String that should be a path within the Online template archive pointing to a translation resource file. If not defined, one of the Translation parts within the Online template is automatically selected. If there are multiple such resources within the archive, there is no guarantee which one of them is selected. |
language | ||
---|---|---|
Required | Value type | EL-evaluated |
No | String | Yes |
If the resolved String is one of the language keys present in the Translation part, only translations of that language are placed into the variable context as a Map. If not defined or the resolved String is blank, all languages present in the Translation part are placed into the variable context as a Map containing Maps. |
Examples
The setTranslation
command is often used in templates to have fixed parts of the document, like headings and labels, translated into different languages. Set the language
attribute to make the expressions in content a bit simpler, as the language doesn't need to specified in that case.
<setTranslation var="translated" language="${docLanguage}">
The translation Map works like any other Map, with expressions in the document content using the translated data referring to the Map's keys. The expressions below would print out a "Greeting" in the selected language - the first one if the language
attribute for setTranslations
is defined, and the second one if not, therefore requiring the language key to be a part of the expression.
<p dyn-content="translated['Greeting']"></p><p dyn-content="translated[docLanguage]['Greeting']"></p>
If the template contains multiple Translation parts, the value
attribute should be used to select which one of them is used. Get the DAP Part value representing a Translation part using an expression with the doc DocumentProperties variable and the name of the Translation part.
<setTranslation var="activeTranslation" value="doc['Translation FI']" /><setTranslation var="activeTranslation" value="doc['Translation DE']" />