/
How do I programmatically switch to another translation?

How do I programmatically switch to another translation?

The translation that is used is determined by page load. There might be a situation where you want to change the translation used after the page has loaded. There is a survey function that can be called in the frontend to programmatically set the translation after page load.

When at least one survey has been triggered on the page, then the following function is also present:srv. The srv function has a method to set the language:

srv.setLanguage(<form_key>,<language>)

This method takes two parameters as input, the first is the form_key of the survey, and the second is the language you want to set.

You can find the survey’s key on the ‘Feedback forms’ page. Click on the icon with the three dots, and click on ‘Copy form key’.

Alternatively, an array of all surveys that are being loaded on a page is present on the srv function as well, it can be accessed here: srv.ALL_KEYS.

The second parameter's value should match the value used in the translations settings in the form builder:

srv.setLanguage(<form_key>,'fr')

If you want to switch back to the original language of the survey, you can use

srv.setLanguage(<form_key>, 'default')

Summary

  • To change to another translation after page load programmatically you can call srv.setLanguage with form_key and translation variable as parameters.

  • This function is only available when at least one survey is triggered on the page.

  • If you want to be able to switch back to the original language, this language should be added as a translation option as well.


Related articles

Related content

Form help articles
Form help articles
More like this
How do I open a Mopinion feedback form with my own button or link?
How do I open a Mopinion feedback form with my own button or link?
Read with this
How do I use the same survey for different languages?
How do I use the same survey for different languages?
More like this
How do I deploy an embedded form?
How do I deploy an embedded form?
Read with this
How do I translate in-app forms?
How do I translate in-app forms?
More like this
How do I deploy my feedback forms?
How do I deploy my feedback forms?
Read with this