oTree Forum >

Multiple languages within a session

#1 by galiya

Hi all,

I would like to run an experiment in two languages. 
I want participants to be able to select the language when starting the experiment. 

How to implement it?
Again, within a game, several participants can have one language, others the other language.

I hope for your suggestions!
Thanks in advance.

#2 by malte_n (edited )

You could try something along this

in _init_.py

 def vars_for_template(player):
        if player.field_maybe_none("language") ==  "english":
            return dict(
                label_value='english label'
            )
        elif player.field_maybe_none("language") ==  "french":
            return dict(
                label_value='french label'
            )
    
    
 on the page
 
 {{formfield 'field_name' label=label_value}}
 
 
 if you want different fields for different languages , try this
 
 {{ if player.language == "english"}}
    {{ formfield 'field_english'}}
{{ else }}
    {{ if player.language == "french"}}
        {{ formfield 'field_french'}}
{{ endif }}


I didn't run this code, but it should give you an general idea, replace "language" with the name of your language field.

Other than this there is a multi-language otree snippet.
https://s3.amazonaws.com/otreehub/browsable_source/1e38462b-46c7-4ca1-bca5-536462f90131/multi_language/index.html
didn't try that though

Write a reply

Set forum username