Skip to main content

Translating text in variables

Learn how to translate words that appear in the variables of an exercise using the function sw_lang.

Max Cohen avatar
Written by Max Cohen
Updated over a week ago

When translating an exercise, we cannot translate the variables of the exercise. There is only one set of variables for all languages. This can cause problems in exercises where words appear in the variables (for example exercises of the type “Text”). For example, we cannot simply translate the variable $answer1, in the image below, to the Dutch word “parabool”.

To solve this issue, we can use a function called sw_lang. The input of this function is a list with words in different languages. The order of the languages is determined as: 1=Dutch

2=English

3=French

4=Spanish

6=Norsk

7=Nynorsk

8=Swedish

9=German

10=Finnish. For example:

$two -> sw_lang([“twee”,”two”,”deux”,”dos”])

If a language is not relevant to you, you can replace the translation of the word with an empty space “”. Irrelevant fields at the end of the list can simply be omitted. For example, the variable from above that we want to translate from English to Dutch could look like

$answer1 -> sw_lang([“parabool”,”parabola”])

There are some words for which all translations are hard-coded into our platform. These words are: “all”, “none”, “yes”, “no”, “indeed” and “not”. They can be accessed as follows:

$yes -> sw_lang(“yes”)

where the variable $yes is defined exactly the same as:

$yes -> sw_lang(["ja","yes","Oui","sí","","Ja","Ja","ja","Ja","Kyllä")

Did this answer your question?