Translations

Video Outline

The translation tag is used to translate the content of a template in different languages. The translation that is shown in the template depends on the language the user has chosen in his Silverfin environment.

Of course these translations won’t happen magically and if you want this to be available, you will have to set translations for all of the text in your template in your code.

Set translations

To make sure that the content of the template is translated in different languages, you need to set a translation by:

  1. indicating the language to which you would like to translate your text; and
  2. adding text in that particular language.

We use the t tag followed by the = sign and the key word for the translation enclosed within single or double quotation marks. We then need to assign the translations after the following codes for all languages (nl: for dutch, fr: for french and en: for english).

In the example below, we used the translation tag to make sure that the word expense is translated to three different languages, i.e. Dutch, French and English.

{% t= "expense" nl:"kost" fr:"les frais" en:"expense" %}

Get translations

To execute the translation anywhere in our code, we will put the key word for the translation placed in brackets with the letter t in front of it.

So we use the t tag and the key word enclosed within single or double quotation marks, but this time without the = sign after t which is used to set the translation.

{% t "expense" %}

Defaults

You probably want most of the texts, placeholders, etc. to be translated when switching your language in Silverfin.

Consider the following code:

{% t="car" nl:"wagen" fr:"voiture" %}
{% t "car" %}

In this case, the English translation is actually not specified, only the Dutch and French translation are. However, “car" (the translation key word) acts here as a default translation for missing languages.

You can overwrite this behaviour by adding a default translation in your translation tag using the keyword default:

{% t="car_t" nl:"wagen" fr:"voiture" default:"car" %}

Variables

In some cases you might want that certain parts of the translation depend on a condition in the template (e.g. the article number of the corporate law). You can create variables inside the translations.

To accomplish this, you will add the variable inside the translation when you are defining the translation, by using this syntax: {{ variable }}.

{% t= "message" en:"This is my sentence with a {{ my_variable }}." %}

And then, when you execute that translation in the code, you need to refer that variable to the one that you want to be displayed in that place.

{% t "message" | my_variable:chosen_variable %}

Let’s look at a concrete example:

{% if modal_aa >= 2019 %}
    {% t= "company_type" en:"COMPANY" nl:"VENNOOTSCHAP" fr:"LA SOCIÉTÉ" %}
    {% capture company_var %}{% t "company_type" %}{% endcapture %}
{% else %}
    {% t= "company_type" en:"ENTERPRISE" nl:"ONDERNEMING" fr:"L'ENTREPRISE" %}
    {% capture company_var %}{% t "company_type" %}{% endcapture %}
{% endif %}


{% t= "message" en:"Number of joint industrial committee responsible for the {{ type_var }}" nl:"Nummers van de paritaire comites die voor de {{ type_var }} bevoegd zijn" fr:"Numéros des commissions paritaires dont dépend {{ type_var }}" %}

{% t "message" | type_var:company_var %}

Conclusion

  • To set a translation we use the t tag with an equal sign and the keyword for the translation between quotes
  • To execute a translation we use the t tag without the equal sign
  • We can define a default translation for languages for which no specific translation has been defined, otherwise the keyword for the translation will be shown in the template
  • We can use variables inside a translation

👍

Remember

If you use translations on your template make sure all parts of the code are adequately translated (e.g. placeholders, infotexts, etc.).