Skip to main content
All CollectionsAuthorsTranslating
Translating text in variables
Translating text in variables

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

Updated over a year ago

When translating an exercise, we cannot translate the variables of the exercise. In exercises where words appear in the variables (for example exercises of the type “Text”), this can cause problems. For example, we cannot simply translate the variable $answer1 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 of size 4 with words in different languages. The first word is in Dutch, the second one in English, the third in French, and the fourth in Spanish. 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 “”. For example, the variable from above that we want to translate from English to Dutch would 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”,”si”])

Did this answer your question?