def get_lang_attr(self): filename = os.path.join(self.locale_dir, self.lang, "LC_MESSAGES", "eduactiv8.mo") # filename = "locale/%s/LC_MESSAGES/eduactiv8.mo" % self.lang self.trans[self.lang] = gettext.GNUTranslations(open(filename, "rb")) try: # print("Opening message file %s for locale %s" % (filename, self.lang) ) self.trans[self.lang] = gettext.GNUTranslations(open(filename, "rb")) except IOError: print("Locale not found. Using default messages") self.trans[self.lang] = gettext.NullTranslations() self.trans[self.lang].install() import i18n.custom.default self.oi18n = i18n.custom.default.I18n() self.kbrd = None self.ltr_text = True self.ltr_numbers = True self.ltr_math = True self.has_uc = True self.has_cursive = True font_variant = 0 self.ico_suffix = "" self.lang_id = 0 # used to identify the language in database - do not reorganize numbers when adding new language if self.lang == 'en_US': import i18n.custom.en_us import i18n.custom.word_lists.en_us_di import i18n.custom.kbrd.en_us import i18n.custom.kbrd.en_course # self.voice = ["-s 170","-a 100","-p 80","-ven-us+m1"] self.voice = ["-ven-us+m1"] self.di = i18n.custom.word_lists.en_us_di.di self.lang_file = i18n.custom.en_us self.kbrd = i18n.custom.kbrd.en_us self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 elif self.lang == 'pl': import i18n.custom.pl import i18n.custom.word_lists.pl_di import i18n.custom.kbrd.pl import i18n.custom.kbrd.pl_course # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vpl+m1"] self.di = i18n.custom.word_lists.pl_di.di self.lang_file = i18n.custom.pl self.kbrd = i18n.custom.kbrd.pl self.kbrd_course_mod = i18n.custom.kbrd.pl_course self.lang_id = 3 elif self.lang == 'sr': import i18n.custom.sr import i18n.custom.word_lists.sr_di # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsr+m1"] self.di = i18n.custom.word_lists.sr_di.di self.lang_file = i18n.custom.sr self.lang_id = 19 self.ico_suffix = "ru" self.has_cursive = False self.time2str_short = self.lang_file.time2str_short elif self.lang == 'ca': import i18n.custom.ca import i18n.custom.word_lists.ca_di self.voice = ["-vca+m1"] self.di = i18n.custom.word_lists.ca_di.di self.lang_file = i18n.custom.ca self.lang_id = 5 elif self.lang == 'es_ES': import i18n.custom.es import i18n.custom.word_lists.es_di self.voice = ["-ves+m1"] self.di = i18n.custom.word_lists.es_di.di self.lang_file = i18n.custom.es self.lang_id = 8 elif self.lang == 'pt_PT': import i18n.custom.pt import i18n.custom.word_lists.pt_di self.voice = ["-vpt-pt+m1"] self.di = i18n.custom.word_lists.pt_di.di self.lang_file = i18n.custom.pt self.lang_id = 9 elif self.lang == 'fr': import i18n.custom.fr import i18n.custom.word_lists.fr_di import i18n.custom.kbrd.fr import i18n.custom.kbrd.fr_course self.voice = ["-vfr+m1"] self.di = i18n.custom.word_lists.fr_di.di self.lang_file = i18n.custom.fr self.kbrd = i18n.custom.kbrd.fr self.kbrd_course_mod = i18n.custom.kbrd.fr_course self.lang_id = 10 elif self.lang == 'it': import i18n.custom.it import i18n.custom.word_lists.it_di self.voice = ["-vit+m1"] self.di = i18n.custom.word_lists.it_di.di self.lang_file = i18n.custom.it self.lang_id = 11 elif self.lang == 'de': import i18n.custom.de import i18n.custom.word_lists.de_di import i18n.custom.kbrd.de import i18n.custom.kbrd.de_course self.voice = ["-vde+m1"] self.di = i18n.custom.word_lists.de_di.di self.lang_file = i18n.custom.de self.kbrd = i18n.custom.kbrd.de self.kbrd_course_mod = i18n.custom.kbrd.de_course self.lang_id = 12 elif self.lang == 'ru': import i18n.custom.ru import i18n.custom.word_lists.ru_di import i18n.custom.kbrd.ru import i18n.custom.kbrd.ru_course # self.voice = ["-s 130","-a 100","-p 80","-vru+m1"] # self.voice = ["-vru+m1"] s 150 -vru self.voice = ["-s 150", "-vru"] self.di = i18n.custom.word_lists.ru_di.di self.lang_file = i18n.custom.ru self.kbrd = i18n.custom.kbrd.ru self.kbrd_course_mod = i18n.custom.kbrd.ru_course self.time2spk = self.lang_file.time2spk self.time2officialstr = self.lang_file.time2officialstr self.time2officialspk = self.lang_file.time2officialspk self.ico_suffix = "ru" self.lang_id = 13 elif self.lang == 'uk': import i18n.custom.uk import i18n.custom.word_lists.uk_di import i18n.custom.kbrd.uk import i18n.custom.kbrd.uk_course self.voice = None self.di = i18n.custom.word_lists.uk_di.di self.lang_file = i18n.custom.uk self.kbrd = i18n.custom.kbrd.uk self.kbrd_course_mod = i18n.custom.kbrd.uk_course self.ico_suffix = "ru" self.lang_id = 14 elif self.lang == 'fi': import i18n.custom.fi import i18n.custom.word_lists.fi_di self.voice = ["-vfi+m1"] self.di = i18n.custom.word_lists.fi_di.di self.lang_file = i18n.custom.fi self.lang_id = 15 elif self.lang == 'el': # Greek import i18n.custom.el import i18n.custom.word_lists.el_di import i18n.custom.kbrd.el import i18n.custom.kbrd.el_course self.voice = ["-vel+m1"] self.di = i18n.custom.word_lists.el_di.di self.lang_file = i18n.custom.el self.kbrd = i18n.custom.kbrd.el self.kbrd_course_mod = i18n.custom.kbrd.el_course self.ico_suffix = "el" self.lang_id = 16 elif self.lang == 'he': # Hebrew import i18n.custom.he import i18n.custom.word_lists.he_di self.voice = ["-ven+m1"] # None self.di = i18n.custom.word_lists.he_di.di self.lang_file = i18n.custom.he self.time2spk = self.lang_file.time2spk self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.he.alpha self.n2spk = self.lang_file.n2spk # font_variant = 1 self.ico_suffix = "he" self.lang_id = 17 elif self.lang == 'lkt': import i18n.custom.lkt import i18n.custom.word_lists.lkt_di self.voice = None self.has_cursive = False self.di = i18n.custom.word_lists.lkt_di.di self.lang_file = i18n.custom.lkt # self.alpha = i18n.custom.cn.alpha # self.n2spk = self.lang_file.n2spk self.ico_suffix = "" self.lang_id = 20 elif self.lang == 'te_ST': import i18n.custom.te_st import i18n.custom.word_lists.te_st_di self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.te_st_di.di self.lang_file = i18n.custom.te_st self.lang_id = 1 else: # self.lang == 'en_GB': import i18n.custom.en_gb import i18n.custom.word_lists.en_gb_di import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.en_gb_di.di self.lang_file = i18n.custom.en_gb self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 # languages that have not been translated are temporarily switched off """ elif self.lang == 'sk': import i18n.custom.sk import i18n.custom.word_lists.sk_di # self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsk+m1"] self.di = i18n.custom.word_lists.sk_di.di self.lang_file = i18n.custom.sk self.lang_id = 4 elif self.lang == 'da': import i18n.custom.da import i18n.custom.word_lists.da_di self.voice = ["-vda+m1"] self.di = i18n.custom.word_lists.da_di.di self.lang_file = i18n.custom.da self.lang_id = 6 elif self.lang == 'nl': import i18n.custom.nl import i18n.custom.word_lists.nl_di self.voice = ["-vnl+m1"] self.di = i18n.custom.word_lists.nl_di.di self.lang_file = i18n.custom.nl self.lang_id = 7 elif self.lang == 'ar': # Arabic import i18n.custom.ar import i18n.custom.word_lists.ar_di self.voice = None self.di = i18n.custom.word_lists.ar_di.di self.lang_file = i18n.custom.ar self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.ar.alpha self.n2spk = self.lang_file.n2spk self.ico_suffix = "ar" self.lang_id = 2 elif self.lang == 'cn': import i18n.custom.cn import i18n.custom.word_lists.cn_di self.voice = None self.di = i18n.custom.word_lists.cn_di.di self.lang_file = i18n.custom.cn # self.alpha = i18n.custom.cn.alpha # self.n2spk = self.lang_file.n2spk self.ico_suffix = "" self.lang_id = 18 """ if self.lang in ["ar", "he"]: self.config.font_multiplier = 1.1 self.config.font_line_height_adjustment = 1.5 self.config.font_start_at_adjustment = 5 else: self.config.font_multiplier = 1 self.config.font_line_height_adjustment = 1 self.config.font_start_at_adjustment = 0 if self.kbrd is None: # self.lang not in ["en_gb","en_us","pl","ru","el","uk","fr"]: import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.d = dict() self.b = dict() self.dp = dict() self.kbrd_course = self.kbrd_course_mod.course self.d.update(self.oi18n.d) self.d.update(self.lang_file.d) self.b.update(self.oi18n.b) self.numbers = self.lang_file.numbers self.numbers2090 = self.lang_file.numbers2090 self.n2txt = self.lang_file.n2txt self.time2str = self.lang_file.time2str if self.lang in ["en_GB", "en_US", "pl"]: self.fract2str = self.lang_file.fract2str self.solid_names = self.oi18n.solid_names self.shape_names = self.oi18n.shape_names self.letter_names = self.lang_file.letter_names self.config.set_font_family(font_variant) if not self.ltr_text: for each_d in [self.d, self.b]: for key in each_d.keys(): if isinstance(each_d[key], list): for index in range(len(each_d[key])): if sys.version_info < (3, 0): if isinstance(each_d[key][index], basestring): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: if isinstance(each_d[key][index], str): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: each_d[key] = reverse(each_d[key], self.alpha, self.lang) for each in [self.solid_names, self.shape_names]: for index in range(len(each)): if sys.version_info < (3, 0): if isinstance(each[index], basestring): each[index] = reverse(each[index], self.alpha, self.lang) else: if isinstance(each[index], str): each[index] = reverse(each[index], self.alpha, self.lang) self.dp.update(self.d) # if self.lang == 'ru' or self.lang == 'he': self.dp.update(self.lang_file.dp) if self.lang == "he": s = unival(self.d['abc_flashcards_word_sequence'][0]) if len(s) > 0: if s[0] == unival("א"): self.d['abc_flashcards_word_sequence'] = self.d['abc_flashcards_word_sequencer'] self.alphabet_lc = self.lang_file.alphabet_lc self.alphabet_uc = self.lang_file.alphabet_uc self.accents_lc = self.lang_file.accents_lc self.accents_uc = self.lang_file.accents_uc
def r(s): return reverse(s, alpha, "he")
def r(s): return reverse(s, "ar")
def r(s): return reverse(s, "he")
def create_game_objects(self, level=1): self.vis_buttons = [1, 1, 1, 1, 1, 1, 1, 0, 0] self.mainloop.info.hide_buttonsa(self.vis_buttons) # create non-movable objects self.board.draw_grid = False h = random.randrange(0, 255, 5) color0 = ex.hsv_to_rgb(h, 40, 230) # highlight 1 font_color = ex.hsv_to_rgb(h, 255, 140) white = (255, 255, 255) # data = [x_count, y_count, number of items on the list, top_quntity,font-size] if self.level.lvl == 1: # images 42x42 data = [20, 14, 3, 3, 2] elif self.level.lvl == 2: data = [20, 14, 3, 5, 2] elif self.level.lvl == 3: data = [20, 14, 3, 7, 2] elif self.level.lvl == 4: data = [20, 14, 4, 3, 2] elif self.level.lvl == 5: data = [20, 14, 4, 5, 2] elif self.level.lvl == 6: data = [20, 14, 4, 7, 2] elif self.level.lvl == 7: data = [20, 14, 5, 3, 2] elif self.level.lvl == 8: data = [20, 14, 5, 5, 2] elif self.level.lvl == 9: data = [20, 14, 6, 3, 2] elif self.level.lvl == 10: data = [20, 14, 6, 5, 2] self.points = data[2] - 2 # rescale the number of squares horizontally to better match the screen width x_count = self.get_x_count(data[1], even=None) if x_count > 20: data[0] = x_count self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1] - 1) self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) shelf_len = 7 # basket basket_w = data[0] - shelf_len - 1 self.board.add_door(data[0] - basket_w, data[1] - 6, basket_w, 5, classes.board.Door, "", white, "") self.board.units[0].door_outline = True # basket image - 260 x 220 img_bg_col = white scheme = "white" if self.mainloop.scheme is not None: if self.mainloop.scheme.dark: scheme = "black" img_bg_col = (0, 0, 0) img_src = os.path.join("schemes", scheme, "basket.png") self.board.add_door(data[0] - 6, data[1] - 6, 6, 5, classes.board.Door, "", img_bg_col, img_src) self.board.units[-1].is_door = False self.board.add_unit(data[0] - 7, 0, 7, 1, classes.board.Label, self.d["Shopping List"], white, "", data[4] + 1) self.board.units[-1].font_color = font_color f_end = ".png" items = ["fr_apple1", "fr_apple2", "fr_strawberry", "fr_pear", "fr_orange", "fr_onion", "fr_tomato", "fr_lemon", "fr_cherry", "fr_pepper", "fr_carrot", "fr_banana", "fr_wmelon"] self.items = items self.img_captions = [] self.singular_items = ["green apple", "red apple", "strawberry", "pear", "orange [fruit]", "onion", "tomato", "lemon", "cherry", "pepper", "carrot", "banana", "watermelon"] for each in self.singular_items: caption = self.lang._n(each, 1) if not self.lang.ltr_text: caption = ex.reverse(self.lang._n(each, 1), self.lang.alpha, self.lang.lang) # caption = self.lang._n(each, 1) if caption is None: caption = "" self.img_captions.append(caption) if self.lang.lang in ["ru", "he"]: self.img_pcaptions = [] si = self.lang.dp["fruit"] for each in si: pcaption = self.lang._n(each, 1) if pcaption is None: pcaption = "" self.img_pcaptions.append(pcaption) else: self.img_pcaptions = self.img_captions item_indexes = [x for x in range(len(items))] self.chosen_items = [[], []] self.solution = {} # pick items and quantities for i in range(data[2]): index = random.randrange(0, len(item_indexes)) self.chosen_items[0].append(item_indexes[index]) quantity = random.randrange(1, data[3] + 1) self.chosen_items[1].append(quantity) self.solution[str(item_indexes[index])] = quantity del (item_indexes[index]) if self.lang.ltr_text: l = [data[0] - 7, data[0] - 6, data[0] - 5] else: l = [data[0] - 1, data[0] - 2, data[0] - 7] # create shopping list for i in range(data[2]): ind = self.chosen_items[0][i] caption = self.lang._n(self.singular_items[ind], self.chosen_items[1][i]) if not self.lang.ltr_text: caption = ex.reverse(caption, self.lang.alpha, self.lang.lang) if caption is None: caption = "" self.board.add_unit(l[0], i + 1, 1, 1, classes.board.Label, str(self.chosen_items[1][i]) + " ", white, "", data[4]) self.board.units[-1].font_color = font_color self.board.add_unit(l[1], i + 1, 1, 1, classes.board.ImgShip, "", (0, 0, 0, 0), os.path.join("fr", items[ind] + f_end), data[4], alpha=True) self.board.add_unit(l[2], i + 1, 5, 1, classes.board.Label, caption, white, "", data[4]) self.board.units[-1].font_color = font_color self.board.ships[i].immobilize() self.board.ships[i].outline = False if self.lang.ltr_text: self.board.units[-1].align = 1 else: self.board.units[-1].align = 2 # rearange z-order of red outlines (shopping list and basket) for i in range(2): self.board.all_sprites_list.move_to_front(self.board.units[i]) # put stuff on shelves: for i in range(len(items)): image = os.path.join("fr", items[i] + f_end) for j in range(0, shelf_len): self.board.add_unit(j, i, 1, 1, classes.board.ImgShip, self.img_captions[i], (0, 0, 0, 0), image, data[4], alpha=True) self.board.ships[-1].audible = False self.board.ships[-1].speaker_val = self.img_pcaptions[i] self.board.ships[-1].speaker_val_update = False self.board.ships[-1].outline = False self.board.all_sprites_list.move_to_front(self.board.units[0]) instruction = self.d["Check the shopping list"] self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter, instruction, color0, "", 3) self.board.ships[-1].set_outline(0, 1) self.board.ships[-1].immobilize() self.board.ships[-1].font_color = font_color self.board.ships[-1].speaker_val = self.dp["Check the shopping list"] self.board.ships[-1].speaker_val_update = False
def get_lang_attr(self): filename = os.path.join(self.locale_dir, self.lang, "LC_MESSAGES", "pysiogame.mo") #filename = "locale/%s/LC_MESSAGES/pysiogame.mo" % self.lang try: #print("Opening message file %s for locale %s" % (filename, self.lang) ) self.trans[self.lang] = gettext.GNUTranslations(open( filename, "rb" ) ) except IOError: print("Locale not found. Using default messages") self.trans[self.lang] = gettext.NullTranslations() self.trans[self.lang].install() import i18n.custom.default self.oi18n = i18n.custom.default.I18n() self.ltr_text = True self.ltr_numbers = True self.ltr_math = True self.has_uc = True self.has_cursive = True font_variant = 0 self.ico_suffix = "" self.lang_id = 0 # used to identify the language in database - do not reorganize numbers when adding new language if self.lang == 'en_US': import i18n.custom.en_us import i18n.custom.word_lists.en_us_di import i18n.custom.kbrd.en_us import i18n.custom.kbrd.en_course #self.voice = ["-s 170","-a 100","-p 80","-ven-us+m1"] self.voice = ["-ven-us+m1"] self.di = i18n.custom.word_lists.en_us_di.di self.lang_file = i18n.custom.en_us self.kbrd = i18n.custom.kbrd.en_us self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 elif self.lang == 'pl': import i18n.custom.pl import i18n.custom.word_lists.pl_di import i18n.custom.kbrd.pl import i18n.custom.kbrd.pl_course #self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vpl+m1"] self.di = i18n.custom.word_lists.pl_di.di self.lang_file = i18n.custom.pl self.kbrd = i18n.custom.kbrd.pl self.kbrd_course_mod = i18n.custom.kbrd.pl_course self.lang_id = 3 elif self.lang == 'sk': import i18n.custom.sk import i18n.custom.word_lists.sk_di #self.voice = ["-s 160","-a 100","-p 80","-vpl+m1"] #"-g 5", self.voice = ["-vsk+m1"] self.di = i18n.custom.word_lists.sk_di.di self.lang_file = i18n.custom.sk self.lang_id = 4 elif self.lang == 'ca': import i18n.custom.ca import i18n.custom.word_lists.ca_di self.voice = ["-vca+m1"] self.di = i18n.custom.word_lists.ca_di.di self.lang_file = i18n.custom.ca self.lang_id = 5 elif self.lang == 'da': import i18n.custom.da import i18n.custom.word_lists.da_di self.voice = ["-vda+m1"] self.di = i18n.custom.word_lists.da_di.di self.lang_file = i18n.custom.da self.lang_id = 6 elif self.lang == 'nl': import i18n.custom.nl import i18n.custom.word_lists.nl_di self.voice = ["-vnl+m1"] self.di = i18n.custom.word_lists.nl_di.di self.lang_file = i18n.custom.nl self.lang_id = 7 elif self.lang == 'es_ES': import i18n.custom.es import i18n.custom.word_lists.es_di self.voice = ["-ves+m1"] self.di = i18n.custom.word_lists.es_di.di self.lang_file = i18n.custom.es self.lang_id = 8 elif self.lang == 'pt_PT': import i18n.custom.pt import i18n.custom.word_lists.pt_di self.voice = ["-vpt-pt+m1"] self.di = i18n.custom.word_lists.pt_di.di self.lang_file = i18n.custom.pt self.lang_id = 9 elif self.lang == 'fr': import i18n.custom.fr import i18n.custom.word_lists.fr_di self.voice = ["-vfr+m1"] self.di = i18n.custom.word_lists.fr_di.di self.lang_file = i18n.custom.fr self.lang_id = 10 elif self.lang == 'it': import i18n.custom.it import i18n.custom.word_lists.it_di self.voice = ["-vit+m1"] self.di = i18n.custom.word_lists.it_di.di self.lang_file = i18n.custom.it self.lang_id = 11 elif self.lang == 'de': import i18n.custom.de import i18n.custom.word_lists.de_di self.voice = ["-vde+m1"] self.di = i18n.custom.word_lists.de_di.di self.lang_file = i18n.custom.de self.lang_id = 12 elif self.lang == 'ru': import i18n.custom.ru import i18n.custom.word_lists.ru_di import i18n.custom.kbrd.ru import i18n.custom.kbrd.ru_course #self.voice = ["-s 130","-a 100","-p 80","-vru+m1"] #self.voice = ["-vru+m1"] s 150 -vru self.voice = ["-s 150","-vru"] self.di = i18n.custom.word_lists.ru_di.di self.lang_file = i18n.custom.ru self.kbrd = i18n.custom.kbrd.ru self.kbrd_course_mod = i18n.custom.kbrd.ru_course self.time2spk = self.lang_file.time2spk self.time2officialstr = self.lang_file.time2officialstr self.time2officialspk = self.lang_file.time2officialspk self.ico_suffix = "ru" self.lang_id = 13 elif self.lang == 'uk': import i18n.custom.uk import i18n.custom.word_lists.uk_di import i18n.custom.kbrd.uk import i18n.custom.kbrd.uk_course self.voice = None self.di = i18n.custom.word_lists.uk_di.di self.lang_file = i18n.custom.uk self.kbrd = i18n.custom.kbrd.uk self.kbrd_course_mod = i18n.custom.kbrd.uk_course self.ico_suffix = "ru" self.lang_id = 14 elif self.lang == 'fi': import i18n.custom.fi import i18n.custom.word_lists.fi_di self.voice = ["-vfi+m1"] self.di = i18n.custom.word_lists.fi_di.di self.lang_file = i18n.custom.fi self.lang_id = 15 elif self.lang == 'el': #Greek import i18n.custom.el import i18n.custom.word_lists.el_di import i18n.custom.kbrd.el import i18n.custom.kbrd.el_course self.voice = ["-vel+m1"] self.di = i18n.custom.word_lists.el_di.di self.lang_file = i18n.custom.el self.kbrd = i18n.custom.kbrd.el self.kbrd_course_mod = i18n.custom.kbrd.el_course self.ico_suffix = "el" self.lang_id = 16 elif self.lang == 'he': #Hebrew import i18n.custom.he import i18n.custom.word_lists.he_di self.voice = ["-ven+m1"]#None self.di = i18n.custom.word_lists.he_di.di self.lang_file = i18n.custom.he self.time2spk = self.lang_file.time2spk self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.he.alpha self.n2spk = self.lang_file.n2spk #font_variant = 1 self.ico_suffix = "he" self.lang_id = 17 elif self.lang == 'ar': #Arabic import i18n.custom.ar import i18n.custom.word_lists.ar_di self.voice = None self.di = i18n.custom.word_lists.ar_di.di self.lang_file = i18n.custom.ar self.ltr_text = False self.has_uc = False self.has_cursive = False self.alpha = i18n.custom.ar.alpha self.n2spk = self.lang_file.n2spk self.ico_suffix = "ar" self.lang_id = 2 elif self.lang == 'te_ST': import i18n.custom.te_st import i18n.custom.word_lists.te_st_di self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.te_st_di.di self.lang_file = i18n.custom.te_st self.lang_id = 1 else:# self.lang == 'en_GB': import i18n.custom.en_gb import i18n.custom.word_lists.en_gb_di import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.en_gb_di.di self.lang_file = i18n.custom.en_gb self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 if self.lang in ["ar","he"]: self.config.font_multiplier = 1.1 self.config.font_line_height_adjustment = 1.5 self.config.font_start_at_adjustment = 5 else: self.config.font_multiplier = 1 self.config.font_line_height_adjustment = 1 self.config.font_start_at_adjustment = 0 if self.lang not in ["en_gb","en_us","pl","ru","el","uk"]: import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.d = dict() self.b = dict() self.dp = dict() self.kbrd_course = self.kbrd_course_mod.course self.d.update(self.oi18n.d) self.d.update(self.lang_file.d) self.b.update(self.oi18n.b) self.numbers = self.lang_file.numbers self.numbers2090 = self.lang_file.numbers2090 self.n2txt = self.lang_file.n2txt self.time2str = self.lang_file.time2str self.solid_names = self.oi18n.solid_names self.shape_names = self.oi18n.shape_names self.letter_names = self.lang_file.letter_names self.config.set_font_family(font_variant) if not self.ltr_text: for each_d in [self.d, self.b]: for key in each_d.keys(): if isinstance(each_d[key], list): for index in range(len(each_d[key])): if sys.version_info < (3, 0): if isinstance(each_d[key][index], basestring): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: if isinstance(each_d[key][index], str): each_d[key][index] = reverse(each_d[key][index], self.alpha, self.lang) else: each_d[key] = reverse(each_d[key], self.alpha, self.lang) for each in [self.solid_names, self.shape_names]: for index in range(len(each)): if sys.version_info < (3, 0): if isinstance(each[index], basestring): each[index] = reverse(each[index], self.alpha, self.lang) else: if isinstance(each[index], str): each[index] = reverse(each[index], self.alpha, self.lang) self.dp.update(self.d) #if self.lang == 'ru' or self.lang == 'he': self.dp.update(self.lang_file.dp) if self.lang == "he": s = unival(self.d['abc_flashcards_word_sequence'][0]) if len(s) > 0: if s[0] == unival("א"): self.d['abc_flashcards_word_sequence'] = self.d['abc_flashcards_word_sequencer'] self.alphabet_lc = self.lang_file.alphabet_lc self.alphabet_uc = self.lang_file.alphabet_uc self.accents_lc = self.lang_file.accents_lc self.accents_uc = self.lang_file.accents_uc
def create_game_objects(self, level=1): self.vis_buttons = [1, 1, 1, 1, 1, 0, 1, 0, 1] self.mainloop.info.hide_buttonsa(self.vis_buttons) # create non-movable objects self.board.draw_grid = False h = random.randrange(0, 255, 5) font_color = ex.hsv_to_rgb(h, 255, 140) white = (255, 255, 255) # data = [x_count, y_count, number of items on the list, top_quantity, font-size] data = [20, 13] data.extend( self.mainloop.xml_conn.get_level_data( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group, self.level.lvl)) self.chapters = self.mainloop.xml_conn.get_chapters( self.mainloop.m.game_dbid, self.mainloop.config.user_age_group) # rescale the number of squares horizontally to better match the screen width x_count = self.get_x_count(data[1], even=None) if x_count > 20: data[0] = x_count self.data = data self.board.set_animation_constraints(0, data[0], 0, data[1]) self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) self.unit_mouse_over = None self.units = [] shelf_len = 7 # basket basket_w = data[0] - shelf_len - 1 self.board.add_door(data[0] - basket_w, data[1] - 5, basket_w, 5, classes.board.Door, "", white, "") self.board.units[0].door_outline = True # basket image - 260 x 220 img_bg_col = white if self.mainloop.scheme is not None: if self.mainloop.scheme.dark: img_bg_col = (0, 0, 0) img_src = "basket.png" self.board.add_door(data[0] - 6, data[1] - 5, 6, 5, classes.board.Door, "", img_bg_col, img_src, door_alpha=True) self.board.units[-1].is_door = False self.board.add_unit(data[0] - 7, 0, 7, 1, classes.board.Label, self.d["Shopping List"], white, "", data[4] + 1) self.board.units[-1].font_color = font_color f_end = ".png" items = [ "fr_apple1", "fr_apple2", "fr_strawberry", "fr_pear", "fr_orange", "fr_onion", "fr_tomato", "fr_lemon", "fr_cherry", "fr_pepper", "fr_carrot", "fr_banana", "fr_wmelon" ] self.items = items self.img_captions = [] self.singular_items = [ "green apple", "red apple", "strawberry", "pear", "orange [fruit]", "onion", "tomato", "lemon", "cherry", "pepper", "carrot", "banana", "watermelon" ] #h_list = [15, 61, 5, 44, 17, 23, 9, 42, 253, 2, 17, 35, 60] self.count_units = [] for each in self.singular_items: caption = self.lang._n(each, 1) if not self.lang.ltr_text: caption = ex.reverse(self.lang._n(each, 1), self.lang.alpha, self.lang.lang) if caption is None: caption = "" self.img_captions.append(caption) if self.lang.lang in ["ru", "he"]: self.img_pcaptions = [] si = self.lang.dp["fruit"] for each in si: pcaption = self.lang._n(each, 1) if pcaption is None: pcaption = "" self.img_pcaptions.append(pcaption) else: self.img_pcaptions = self.img_captions item_indexes = [x for x in range(len(items))] self.chosen_items = [[], []] self.solution = {} # pick items and quantities for i in range(data[2]): index = random.randrange(0, len(item_indexes)) self.chosen_items[0].append(item_indexes[index]) quantity = random.randrange(1, data[3] + 1) self.chosen_items[1].append(quantity) self.solution[str(item_indexes[index])] = quantity del (item_indexes[index]) if self.lang.ltr_text: l = [data[0] - 7, data[0] - 6, data[0] - 5] else: l = [data[0] - 1, data[0] - 2, data[0] - 7] # create shopping list for i in range(data[2]): ind = self.chosen_items[0][i] caption = self.lang._n(self.singular_items[ind], self.chosen_items[1][i]) if not self.lang.ltr_text: caption = ex.reverse(caption, self.lang.alpha, self.lang.lang) if caption is None: caption = "" self.board.add_unit(l[0], i + 1, 1, 1, classes.board.Label, str(self.chosen_items[1][i]) + " ", white, "", data[4]) self.board.units[-1].font_color = font_color self.board.units[-1].checkable = True self.board.units[-1].init_check_images(1, 1.5) self.count_units.append(len(self.board.units)) self.board.add_unit(l[1], i + 1, 1, 1, classes.board.ImgShip, "", (0, 0, 0, 0), os.path.join("fr", items[ind] + f_end), data[4], alpha=True) self.board.add_unit(l[2], i + 1, 5, 1, classes.board.Label, caption, white, "", data[4]) self.board.units[-1].font_color = font_color self.board.ships[i].immobilize() self.board.ships[i].outline = False if self.lang.ltr_text: self.board.units[-1].align = 1 else: self.board.units[-1].align = 2 # rearange z-order of red outlines (shopping list and basket) for i in range(2): self.board.all_sprites_list.move_to_front(self.board.units[i]) if self.mainloop.scheme is None: dc_img_src = os.path.join('unit_bg', "dc_hover_wb.png") else: if self.mainloop.scheme.dark: dc_img_src = os.path.join('unit_bg', "dc_hover_bw.png") else: dc_img_src = os.path.join('unit_bg', "dc_hover_wb.png") dc_tint_color = ex.hsv_to_rgb(253, self.mainloop.cl.bg_color_s, self.mainloop.cl.bg_color_v) # put stuff on shelves: for i in range(len(items)): image = os.path.join("fr", items[i] + f_end) for j in range(0, shelf_len): self.board.add_universal_unit(grid_x=j, grid_y=i, grid_w=1, grid_h=1, txt=self.img_captions[i], fg_img_src=None, bg_img_src=image, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0), border_color=None, font_color=None, bg_tint_color=None, fg_tint_color=None, dc_tint_color=dc_tint_color, txt_align=(0, 0), font_type=0, multi_color=False, alpha=True, immobilized=False, dc_as_hover=True, mode=0) self.board.ships[-1].audible = False self.board.ships[-1].speaker_val = self.img_pcaptions[i] self.board.ships[-1].speaker_val_update = False self.units.append(self.board.ships[-1]) self.board.all_sprites_list.move_to_front(self.board.units[0])
def r(s): return reverse(s, alpha, "he")
def create_game_objects(self, level=1): self.vis_buttons = [1, 1, 1, 1, 1, 1, 1, 0, 0] self.mainloop.info.hide_buttonsa(self.vis_buttons) #create non-movable objects self.board.draw_grid = False h = random.randrange(0, 255, 5) color0 = ex.hsv_to_rgb(h, 40, 230) #highlight 1 font_color = ex.hsv_to_rgb(h, 255, 140) white = (255, 255, 255) #data = [x_count, y_count, number of items on the list, top_quntity,font-size] if self.level.lvl == 1: #images 42x42 data = [20, 14, 3, 3, 2] elif self.level.lvl == 2: data = [20, 14, 3, 5, 2] elif self.level.lvl == 3: data = [20, 14, 3, 7, 2] elif self.level.lvl == 4: data = [20, 14, 4, 3, 2] elif self.level.lvl == 5: data = [20, 14, 4, 5, 2] elif self.level.lvl == 6: data = [20, 14, 4, 7, 2] elif self.level.lvl == 7: data = [20, 14, 5, 3, 2] elif self.level.lvl == 8: data = [20, 14, 5, 5, 2] elif self.level.lvl == 9: data = [20, 14, 6, 3, 2] elif self.level.lvl == 10: data = [20, 14, 6, 5, 2] self.points = data[2] - 2 #rescale the number of squares horizontally to better match the screen width x_count = self.get_x_count(data[1], even=None) if x_count > 20: data[0] = x_count self.data = data self.layout.update_layout(data[0], data[1]) self.board.level_start(data[0], data[1], self.layout.scale) shelf_len = 7 #basket basket_w = data[0] - shelf_len - 1 self.board.add_door(data[0] - basket_w, data[1] - 6, basket_w, 5, classes.board.Door, "", white, "") self.board.units[0].door_outline = True #basket image - 260 x 220 img_bg_col = white scheme = "white" if self.mainloop.scheme is not None: if self.mainloop.scheme.dark: scheme = "black" img_bg_col = (0, 0, 0) img_src = os.path.join("schemes", scheme, "basket.png") self.board.add_door(data[0] - 6, data[1] - 6, 6, 5, classes.board.Door, "", img_bg_col, img_src) self.board.add_unit(data[0] - 7, 0, 7, 1, classes.board.Label, self.d["Shopping List"], white, "", data[4] + 1) f_end = ".png" items = [ "fr_apple1", "fr_apple2", "fr_strawberry", "fr_pear", "fr_orange", "fr_onion", "fr_tomato", "fr_lemon", "fr_cherry", "fr_pepper", "fr_carrot", "fr_banana", "fr_wmelon" ] self.items = items self.img_captions = [] self.singular_items = [ "green apple", "red apple", "strawberry", "pear", "orange [fruit]", "onion", "tomato", "lemon", "cherry", "pepper", "carrot", "banana", "watermelon" ] for each in self.singular_items: caption = self.lang._n(each, 1) if not self.lang.ltr_text: caption = ex.reverse(self.lang._n(each, 1), self.lang.alpha, self.lang.lang) #caption = self.lang._n(each, 1) if caption is None: caption = "" self.img_captions.append(caption) if self.lang.lang in ["ru", "he"]: self.img_pcaptions = [] si = self.lang.dp["fruit"] for each in si: pcaption = self.lang._n(each, 1) if pcaption is None: pcaption = "" self.img_pcaptions.append(pcaption) else: self.img_pcaptions = self.img_captions item_indexes = [x for x in range(len(items))] self.chosen_items = [[], []] self.solution = {} #pick items and quantities for i in range(data[2]): index = random.randrange(0, len(item_indexes)) self.chosen_items[0].append(item_indexes[index]) quantity = random.randrange(1, data[3] + 1) self.chosen_items[1].append(quantity) self.solution[str(item_indexes[index])] = quantity del (item_indexes[index]) if self.lang.ltr_text: l = [data[0] - 7, data[0] - 6, data[0] - 5] else: l = [data[0] - 1, data[0] - 2, data[0] - 7] #create shopping list for i in range(data[2]): ind = self.chosen_items[0][i] caption = self.lang._n(self.singular_items[ind], self.chosen_items[1][i]) if not self.lang.ltr_text: caption = ex.reverse(caption, self.lang.alpha, self.lang.lang) if caption is None: caption = "" self.board.add_unit(l[0], i + 1, 1, 1, classes.board.Label, str(self.chosen_items[1][i]) + " ", white, "", data[4]) self.board.add_unit( l[1], i + 1, 1, 1, classes.board.ImgShip, "", white, os.path.join("schemes", scheme, items[ind] + f_end), data[4]) self.board.add_unit(l[2], i + 1, 5, 1, classes.board.Label, caption, white, "", data[4]) self.board.ships[i].immobilize() self.board.ships[i].outline = False if self.lang.ltr_text: self.board.units[-1].align = 1 else: self.board.units[-1].align = 2 #rearange z-order of red outlines (shopping list and basket) for i in range(2): self.board.all_sprites_list.move_to_front(self.board.units[i]) #put stuff on shelves: for i in range(len(items)): image = os.path.join("schemes", scheme, items[i] + f_end) for j in range(0, shelf_len): self.board.add_unit(j, i, 1, 1, classes.board.ImgShip, self.img_captions[i], white, image, data[4]) self.board.ships[-1].audible = False self.board.ships[-1].speaker_val = self.img_pcaptions[i] self.board.ships[-1].speaker_val_update = False self.board.all_sprites_list.move_to_front(self.board.units[0]) instruction = self.d["Check the shopping list"] self.board.add_unit(0, data[1] - 1, data[0], 1, classes.board.Letter, instruction, color0, "", 3) self.board.ships[-1].set_outline(0, 1) self.board.ships[-1].immobilize() self.board.ships[-1].font_color = font_color self.board.ships[-1].speaker_val = self.dp["Check the shopping list"] self.board.ships[-1].speaker_val_update = False
def get_lang_attr(self, login=False): filename = os.path.join(self.locale_dir, self.lang, "LC_MESSAGES", "eduactiv8.mo") try: self.trans[self.lang] = gettext.GNUTranslations( open(filename, "rb")) except IOError: print("Locale not found. Using default messages") self.trans[self.lang] = gettext.NullTranslations() self.trans[self.lang].install() import i18n.custom.default self.oi18n = i18n.custom.default.I18n() self.kbrd = None self.ltr_text = True self.ltr_numbers = True self.ltr_math = True self.has_uc = True self.has_cursive = True font_variant = 0 self.ico_suffix = "" self.lang_id = 0 # used to identify the language in database - do not reorganize numbers when adding new language lang = self.xml_langs.get_lang_config(self.lang) self.tts_disabled_lngs = self.xml_langs.get_tts_disabled() if lang is not None: if lang.attrib['voice_mb'] != "None" and lang.attrib[ 'use_mb'] == "True": self.voice = eval(lang.attrib["voice_mb"]) elif lang.attrib['voice'] != "None": self.voice = eval(lang.attrib["voice"]) else: self.voice = None code_lc = self.lang.lower() if sys.version_info < (3, 0): exec("import i18n.custom." + code_lc) if not login: exec("import i18n.custom.word_lists." + code_lc + "_di") exec("import i18n.custom.a4a_py." + self.lang + " as a4a_word_lst") if ast.literal_eval(lang.attrib['has_keyboard']) is True: exec("import i18n.custom.kbrd." + code_lc) exec("import i18n.custom.kbrd." + code_lc[0:2] + "_course") self.kbrd = eval("i18n.custom.kbrd." + code_lc) self.kbrd_course_mod = eval("i18n.custom.kbrd." + code_lc[0:2] + "_course") self.di = eval("i18n.custom.word_lists." + code_lc + "_di.di") else: import importlib importlib.import_module("i18n.custom." + code_lc) if not login: importlib.import_module("i18n.custom.word_lists." + code_lc + "_di") importlib.import_module("i18n.custom.a4a_py." + self.lang) a4a_word_lst = eval("i18n.custom.a4a_py." + self.lang) if ast.literal_eval(lang.attrib['has_keyboard']) is True: importlib.import_module("i18n.custom.kbrd." + code_lc) importlib.import_module("i18n.custom.kbrd." + code_lc[0:2] + "_course") self.kbrd = eval("i18n.custom.kbrd." + code_lc) self.kbrd_course_mod = eval("i18n.custom.kbrd." + code_lc[0:2] + "_course") self.di = eval("i18n.custom.word_lists." + code_lc + "_di.di") self.lang_file = eval("i18n.custom." + code_lc) self.lang_id = int(lang.attrib["id"]) self.ltr_text = ast.literal_eval(lang.attrib['ltr']) self.has_uc = ast.literal_eval(lang.attrib['has_uc']) self.has_cursive = ast.literal_eval(lang.attrib['has_cursive']) self.ico_suffix = lang.attrib['ico_suffix'] else: print("Language file not found.") import i18n.custom.en_gb import i18n.custom.word_lists.en_gb_di import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course import i18n.custom.a4a_py.en_GB as a4a_word_lst self.voice = ["-ven+m1"] self.di = i18n.custom.word_lists.en_gb_di.di self.lang_file = i18n.custom.en_gb self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.lang_id = 1 if self.lang == 'sr': self.time2str_short = self.lang_file.time2str_short elif self.lang == 'ru': self.time2spk_short = self.lang_file.time2spk_short self.time2str_short = self.lang_file.time2str_short self.time2spk = self.lang_file.time2spk elif self.lang == 'he': self.time2spk = self.lang_file.time2spk self.alpha = i18n.custom.he.alpha self.n2spk = self.lang_file.n2spk elif self.lang == 'ar': self.alpha = None self.n2spk = self.lang_file.n2spk if self.lang in ["ar", "he"]: self.config.font_multiplier = 1.1 self.config.font_line_height_adjustment = 1.5 self.config.font_start_at_adjustment = 5 else: self.config.font_multiplier = 1 self.config.font_line_height_adjustment = 1 self.config.font_start_at_adjustment = 0 if self.kbrd is None: import i18n.custom.kbrd.en_gb import i18n.custom.kbrd.en_course self.kbrd = i18n.custom.kbrd.en_gb self.kbrd_course_mod = i18n.custom.kbrd.en_course self.d = dict() self.b = dict() self.dp = dict() self.b.update(self.oi18n.b) if not login: self.kbrd_course = self.kbrd_course_mod.course self.d.update(self.oi18n.d) self.d.update(self.lang_file.d) self.numbers = self.lang_file.numbers self.numbers2090 = self.lang_file.numbers2090 self.n2txt = self.lang_file.n2txt self.time2str = self.lang_file.time2str self.fract2str = self.lang_file.fract2str self.solid_names = self.oi18n.solid_names self.shape_names = self.oi18n.shape_names self.letter_names = self.lang_file.letter_names self.config.set_font_family(font_variant) if not self.ltr_text: for each_d in [self.d, self.b]: for key in each_d.keys(): if isinstance(each_d[key], list): for index in range(len(each_d[key])): if sys.version_info < (3, 0): if isinstance(each_d[key][index], basestring): each_d[key][index] = reverse( each_d[key][index], self.lang) else: if isinstance(each_d[key][index], str): each_d[key][index] = reverse( each_d[key][index], self.lang) else: each_d[key] = reverse(each_d[key], self.lang) for each in [self.solid_names, self.shape_names]: for index in range(len(each)): if sys.version_info < (3, 0): if isinstance(each[index], basestring): each[index] = reverse(each[index], self.lang) else: if isinstance(each[index], str): each[index] = reverse(each[index], self.lang) self.dp.update(self.d) self.dp.update(self.lang_file.dp) if not login and self.lang == "he": s = unival(self.d['abc_flashcards_word_sequence'][0]) if len(s) > 0: if s[0] == unival("א"): self.d['abc_flashcards_word_sequence'] = self.d[ 'abc_flashcards_word_sequencer'] self.alphabet_lc = self.lang_file.alphabet_lc self.accents_lc = self.lang_file.accents_lc if self.has_uc: self.alphabet_uc = self.lang_file.alphabet_uc self.accents_uc = self.lang_file.accents_uc else: self.alphabet_uc = self.accents_lc self.accents_uc = self.accents_lc if not login: self.d["a4a_animals"] = a4a_word_lst.d["a4a_animals"] self.d["a4a_sport"] = a4a_word_lst.d["a4a_sport"] self.d["a4a_body"] = a4a_word_lst.d["a4a_body"] self.d["a4a_people"] = a4a_word_lst.d["a4a_people"] self.d["a4a_food"] = a4a_word_lst.d["a4a_food"] self.d["a4a_clothes_n_accessories"] = a4a_word_lst.d[ "a4a_clothes_n_accessories"] self.d["a4a_actions"] = a4a_word_lst.d["a4a_actions"] self.d["a4a_construction"] = a4a_word_lst.d["a4a_construction"] self.d["a4a_nature"] = a4a_word_lst.d["a4a_nature"] self.d["a4a_jobs"] = a4a_word_lst.d["a4a_jobs"] self.d["a4a_fruit_n_veg"] = a4a_word_lst.d["a4a_fruit_n_veg"] self.d["a4a_transport"] = a4a_word_lst.d["a4a_transport"]