limesurvey

Get current language session when filling a survey


I have a multilingual survey in French and English and some questions are only relevant for French speakers. The thing is I am not sure by advance of the language chosen by the user.

For now I use the language attribute when importing my participants and filter the English questions according to this parameter.

It works well when a participant that I set English wants finally to fill the questionnaire in French : all the questions appear.

The problem comes with the opposite case : the French questions don't disappear when a participant that I set initially in French decides to fill the questionnaire in English.

The solution I would like to have is to detect the language chosen by the user in the session and hide consequently the questions.

I found this documentation : https://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Language-specific_Javascript_code

But the alert function only works with the default language of the survey (only French in my case)


Solution

  • You can use LANG , it's a core variable added for all survey. See https://github.com/LimeSurvey/LimeSurvey/blob/2f7345fb31768e872618831e6b7ce47c8b42b23f/application/helpers/replacements_helper.php#L690 .

    Then LANG == 'fr' in relevance equation for question only for french user.

    The LANG can be show red in administration, but always work for public.