import random from otree.api import * from settings import LANGUAGE_CODE doc = """ How to translate an app to multiple languages (e.g. English and German). There are 2 ways to define localizable strings: (1) Put it in a "lexicon" file (see lexicon_en.py, lexicon_de.py). This is the easiest technique, and it allows you to easily reuse the same string multiple times. (2) If the string contains variables, then it should to be defined in the template. Use an if-statement, like {{ if de }} Nein {{ else }} No {{ endif }} When you change the LANGUAGE_CODE in settings.py, the language will automatically be changed. Note: this technique does not require .po files, which are a more complex technique. """ if LANGUAGE_CODE == 'de': from .lexicon_de import Lexicon else: from .lexicon_en import Lexicon # this is the dict you should pass to each page in vars_for_template, # enabling you to do if-statements like {{ if de }} Nein {{ else }} No {{ endif }} which_language = {'en': False, 'de': False, 'zh': False} # noqa which_language[LANGUAGE_CODE[:2]] = True class C(BaseConstants): NAME_IN_URL = 'bret_language' NUM_ROUNDS = 1 PLAYERS_PER_GROUP = None class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): boxes_collected = models.IntegerField(label=Lexicon.boxes_collected) class Game(Page): form_model = 'player' form_fields = ['boxes_collected'] @staticmethod def vars_for_template(player: Player): return dict(Lexicon=Lexicon, **which_language) class Results(Page): @staticmethod def vars_for_template(player: Player): # this is just fake data return dict( boxes_total=64, bomb_row=2, bomb_col=1, bomb=True, payoff=player.payoff, box_value=cu(5), boxes_collected=player.boxes_collected, Lexicon=Lexicon, **which_language ) page_sequence = [Game, Results]