def _update_scenario_translation_infos(self, scenario): """Fill in translation infos of selected scenario to translation label.""" try: metadata = ScenarioEventHandler.get_metadata_from_file(scenario) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return translation_status = metadata.get('translation_status', u'') lbl = self._gui.findChild(name="translation_status") lbl.text = translation_status lbl = self._gui.findChild(name="uni_map_difficulty") #xgettext:python-format lbl.text = _("Difficulty: {difficulty}").format( difficulty=metadata['difficulty']) lbl = self._gui.findChild(name="uni_map_author") #xgettext:python-format lbl.text = _("Author: {author}").format(author=metadata['author']) lbl = self._gui.findChild(name="uni_map_desc") #xgettext:python-format lbl.text = _("Description: {desc}").format( desc=metadata['description'])
def _update_infos(self): """Fill in infos of selected scenario to label""" lang_list = self._gui.findChild(name="uni_langlist") cur_selected_language = lang_list.selected_item lang_list.items = self._get_available_languages() if cur_selected_language in lang_list.items: lang_list.selected = lang_list.items.index(cur_selected_language) else: lang_list.selected = 0 cur_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) translated_scenario = self._find_map_filename(cur_locale) if os.path.exists(translated_scenario): self._update_scenario_translation_infos(translated_scenario) else: try: default_locale, default_encoding = locale.getdefaultlocale() except ValueError: # OS X sometimes returns 'UTF-8' as locale, which is a ValueError default_locale = 'en' possibilities = [ # try to find a file for the system locale before falling back to en default_locale, default_locale.split('_')[0], 'en', ] lang_list.selected = 0 for lang in possibilities: if LANGUAGENAMES[lang] in lang_list.items: lang_list.selected = lang_list.items.index(LANGUAGENAMES[lang]) break try: difficulty, author, desc = ScenarioEventHandler.get_metadata_from_file(self._get_selected_map()) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return lbl = self._gui.findChild(name="uni_map_difficulty") #xgettext:python-format lbl.text = _("Difficulty: {difficulty}").format(difficulty=difficulty) lbl = self._gui.findChild(name="uni_map_author") #xgettext:python-format lbl.text = _("Author: {author}").format(author=author) lbl = self._gui.findChild(name="uni_map_desc") #xgettext:python-format lbl.text = _("Description: {desc}").format(desc=desc)
def _update_scenario_infos(self): """Fill in infos of selected scenario to label""" lang_list = self.current.findChild(name="uni_langlist") cur_selected_language = lang_list.selected_item lang_list.items = self._get_available_languages() if cur_selected_language in lang_list.items: lang_list.selected = lang_list.items.index(cur_selected_language) else: lang_list.selected = 0 cur_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) translated_scenario = self._find_map_filename(cur_locale) if os.path.exists(translated_scenario): self._update_scenario_translation_infos(translated_scenario) else: try: default_locale, default_encoding = locale.getdefaultlocale() except ValueError: # OS X sometimes returns 'UTF-8' as locale, which is a ValueError default_locale = 'en' possibilities = [ # try to find a file for the system locale before falling back to en default_locale, default_locale.split('_')[0], 'en', ] for lang in possibilities: if LANGUAGENAMES[lang] in lang_list.items: lang_list.selected = lang_list.items.index( LANGUAGENAMES[lang]) break else: # (for-else: else only runs if no break occured) select first one lang_list.selected = 0 try: difficulty, author, desc = \ ScenarioEventHandler.get_metadata_from_file( self._get_selected_map() ) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return #xgettext:python-format self.current.findChild(name="uni_map_difficulty").text = \ _("Difficulty: {difficulty}").format(difficulty=difficulty) #xgettext:python-format self.current.findChild(name="uni_map_author").text = \ _("Author: {author}").format(author=author) #xgettext:python-format self.current.findChild(name="uni_map_desc").text = \ _("Description: {desc}").format(desc=desc)
def _update_scenario_translation_infos(self, scenario): """Fill in translation infos of selected scenario to translation label.""" try: metadata = ScenarioEventHandler.get_metadata_from_file(scenario) except InvalidScenarioFileFormat as e: self._show_invalid_scenario_file_popup(e) return translation_status = metadata.get('translation_status', u'') lbl = self._gui.findChild(name="translation_status") lbl.text = translation_status lbl = self._gui.findChild(name="uni_map_difficulty") lbl.text = _("Difficulty: {difficulty}").format(difficulty=metadata['difficulty']) lbl = self._gui.findChild(name="uni_map_author") lbl.text = _("Author: {author}").format(author=metadata['author']) lbl = self._gui.findChild(name="uni_map_desc") lbl.text = _("Description: {desc}").format(desc=metadata['description'])