def update_languages(self, data=None): if data is None: data = self._setting.get(UH_MODULE, "Language") languages_map = dict(find_available_languages()) languages_map['System default'] = '' symbol = None if data == unicode('System default'): symbol = 'System default' else: for key, value in LANGUAGENAMES.iteritems(): if value == data: symbol = key assert symbol is not None, "Something went badly wrong with the translation update!" + \ " Searching for: " + str(data) + " in " + str(LANGUAGENAMES) index = sorted(languages_map.keys()).index(symbol) name, position = sorted(languages_map.items())[index] try: if name != 'System default': trans = gettext.translation('unknownhorizons', position, languages=[name]) trans.install(unicode=1) else: gettext.install('unknownhorizons', 'build/mo', unicode=1) name = '' except IOError: print _("Configured language %(lang)s at %(place)s could not be loaded") % {'lang': settings.language.name, 'place': settings.language.position} install('unknownhorizons', 'build/mo', unicode=1) self._setting.set(UH_MODULE, "Language", 'System default') update_all_translations()
def set(self, module, name, val, extra_attrs=None): if extra_attrs is None: extra_attrs = {} # that's bad to have as default value # catch events for settings that should be displayed in another way than they should be saved if module == UH_MODULE and name == "Language": val = LANGUAGENAMES.get_by_value(val) return super(SettingsDialog, self).set(module, name, val, extra_attrs)
def _update_infos(self, selected_language=None): # type: (Optional[str]) -> None """ Check if selected language is available or pick a fallback language. Fill in infos of selected scenario. """ scenario_idx = self._gui.findChild(name="maplist").selected_item scenario = self._scenarios[scenario_idx] lang_list = self._gui.findChild(name="uni_langlist") selected_language = selected_language if selected_language is not None else lang_list.selected_item available_languages = self.get_available_languages(scenario) if selected_language not in available_languages: selected_language = LANGUAGENAMES[ self.guess_suitable_default_locale(available_languages)] self._language_fallback_active = True else: self._language_fallback_active = False lang_list.items = available_languages lang_list.selected = available_languages.index(selected_language) selected_language_code = LANGUAGENAMES.get_by_value(selected_language) translated_scenario = self.find_map_filename(scenario, selected_language_code) if translated_scenario is None: return self._update_scenario_translation_infos(translated_scenario)
def update_authors_per_file(input_po, regexp=LANG_RE, since='weblate-credits..', pushed_by='Weblate'): authors = subprocess.check_output( [ 'git', 'shortlog', since, '--committer', pushed_by, '-sn', # Use 'sne' to include email (if that is ever needed) '--', input_po, ], stderr=subprocess.STDOUT) #TODO Clearly the above can never fail, ever. But what if it did? lang = regexp.search(input_po).groups()[0] for author_line in authors.split('\n'): if not author_line: continue author = JUST_NAME.search(author_line).groups()[0] if author in GLOBAL_AUTHORS: continue english_lang = LANGUAGENAMES.get_english(lang) language_authors[english_lang].add(author)
def _update_infos(self, selected_language=None): # type: (Optional[str]) -> None """ Check if selected language is available or pick a fallback language. Fill in infos of selected scenario. """ scenario_idx = self._gui.findChild(name="maplist").selected_item scenario = self._scenarios[scenario_idx] lang_list = self._gui.findChild(name="uni_langlist") selected_language = selected_language if selected_language is not None else lang_list.selected_item available_languages = self.get_available_languages(scenario) if selected_language not in available_languages: selected_language = LANGUAGENAMES[self.guess_suitable_default_locale(available_languages)] self._language_fallback_active = True else: self._language_fallback_active = False lang_list.items = available_languages lang_list.selected = available_languages.index(selected_language) selected_language_code = LANGUAGENAMES.get_by_value(selected_language) translated_scenario = self.find_map_filename(scenario, selected_language_code) if translated_scenario is None: return self._update_scenario_translation_infos(translated_scenario)
def get_locale(self): for locale_code, langname in LANGUAGENAMES.items(): if langname == self.get_uh_setting('Language'): return locale_code # TODO : better way to find 'System default' ? default_locale, default_encoding = locale.getdefaultlocale() return default_locale.split('_')[0]
def _find_map_filename(locale = None): """Finds the selected map's filename with its locale.""" this_locale = "" new_map_name = "" if locale is None: this_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) else: this_locale = locale #check if selected map's file ends with .yaml if self._get_selected_map().find('.yaml') == -1: new_map_name = self._get_selected_map() + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension #if selected map's file ends with .yaml then get current locale #to remove locale postfix from selected_map's name else: #get current locale to split current map file name current_locale = yamlcache.YamlCache.get_file(self._get_selected_map(), \ game_data=True)['locale'] new_map_name = self._get_selected_map()[:self._get_selected_map().\ find('_' + current_locale)] + '_' + \ this_locale + '.' + \ SavegameManager.scenario_extension return new_map_name
def update_languages(self, data=None): """ Load/Change language of Unknown Horizons. Called on startup and when changing the language. data is used when changing the language in the settings menu. """ if data is None: data = self._setting.get(UH_MODULE, "Language") languages_map = dict(find_available_languages()) languages_map['System default'] = '' # English is not shipped as .mo file. languages_map['en'] = '' symbol = None if data == unicode('System default'): symbol = 'System default' else: for key, value in LANGUAGENAMES.iteritems(): if value == data: symbol = key assert symbol is not None, "Something went badly wrong with the translation update!" + \ " Searching for: " + str(data) + " in " + str(LANGUAGENAMES) try: index = sorted(languages_map.keys()).index(symbol) # This only happens on startup when the language is not available # (either from the settings file or $LANG). except ValueError: print "Language %s is not available!" % data index = sorted(languages_map.keys()).index('System default') # Reset the language or the settings crashes. self._setting.set(UH_MODULE, "Language", 'System default') name, position = sorted(languages_map.items())[index] try: if name != 'System default': # English is not shipped as .mo file, thus if English is # selected we use NullTranslations to get English output. fallback = name == 'en' trans = gettext.translation('unknownhorizons', position, languages=[name], fallback=fallback) trans.install(unicode=True) else: gettext.install('unknownhorizons', 'build/mo', unicode=True) name = '' except IOError: print _( "Configured language %(lang)s at %(place)s could not be loaded" ) % { 'lang': name, 'place': position } gettext.install('unknownhorizons', 'build/mo', unicode=True) self._setting.set(UH_MODULE, "Language", 'System default') update_all_translations()
def get_locale(self): for locale_code, langname in LANGUAGENAMES.items(): if langname == self.get_uh_setting('Language'): return locale_code default_locale, default_encoding = locale.getdefaultlocale() try: return default_locale.split('_')[0] except: # If default locale could not be detected use 'EN' as fallback return "en"
def get_locale(self): for locale_code, langname in LANGUAGENAMES.items(): if langname == self.get_uh_setting('Language'): if not langname == 'System default': return locale_code try: default_locale, default_encoding = locale.getdefaultlocale() return default_locale.split('_')[0] except ValueError: # OS X sometimes returns 'UTF-8' as locale, which is a ValueError # If default locale could not be detected use 'EN' as fallback return "en"
def update_languages(self, data=None): """ Load/Change language of Unknown Horizons. Called on startup and when changing the language. data is used when changing the language in the settings menu. """ if data is None: data = self._setting.get(UH_MODULE, "Language") languages_map = dict(find_available_languages()) languages_map['System default'] = '' # English is not shipped as .mo file. languages_map['en'] = '' symbol = None if data == unicode('System default'): symbol = 'System default' else: for key, value in LANGUAGENAMES.iteritems(): if value == data: symbol = key assert symbol is not None, "Something went badly wrong with the translation update!" + \ " Searching for: " + str(data) + " in " + str(LANGUAGENAMES) try: index = sorted(languages_map.keys()).index(symbol) # This only happens on startup when the language is not available # (either from the settings file or $LANG). except ValueError: print "Language %s is not available!" % data index = sorted(languages_map.keys()).index('System default') # Reset the language or the settings crashes. self._setting.set(UH_MODULE, "Language", 'System default') name, position = sorted(languages_map.items())[index] try: if name != 'System default': # English is not shipped as .mo file, thus if English is # selected we use NullTranslations to get English output. fallback = name == 'en' trans = gettext.translation('unknown-horizons', position, languages=[name], fallback=fallback) trans.install(unicode=True, names=['ngettext',]) else: if platform.system() == "Windows": # win doesn't set the language variable by default os.environ[ 'LANGUAGE' ] = locale.getdefaultlocale()[0] gettext.install('unknown-horizons', 'content/lang', unicode=True, names=['ngettext',]) name = '' except IOError: print _("Configured language %(lang)s at %(place)s could not be loaded") % {'lang': name, 'place': position} gettext.install('unknown-horizons', 'content/lang', unicode=True, names=['ngettext',]) self._setting.set(UH_MODULE, "Language", 'System default') update_all_translations()
def _on_Language_changed(self, widget): value = widget.items[widget.getData()] language_code = LANGUAGENAMES.get_by_value(value) status_label = self.widget.findChild(name='language_translation_status') if not language_code or language_code == 'en': status_label.text = '' else: value = get_language_translation_stats(language_code) if value: status_label.text = T('Translation {percentage}% completed').format(percentage=value) else: status_label.text = ''
def get_locale(self): langname = self.get_uh_setting("Language") locale_code = LANGUAGENAMES.get_by_value(langname) if not langname == "System default": return locale_code try: default_locale, default_encoding = locale.getdefaultlocale() return default_locale.split("_")[0] except (ValueError, AttributeError): # OS X sometimes returns 'UTF-8' as locale, which is a ValueError. # If no locale is set at all, the split will fail, which is an AttributeError. # Use 'EN' as fallback in both cases since we cannot reasonably detect the locale. return "en"
def get_locale(self): for locale_code, langname in LANGUAGENAMES.items(): if langname == self.get_uh_setting('Language'): if not langname == 'System default': return locale_code try: default_locale, default_encoding = locale.getdefaultlocale() return default_locale.split('_')[0] except (ValueError, AttributeError): # OS X sometimes returns 'UTF-8' as locale, which is a ValueError. # If no locale is set at all, the split will fail, which is an AttributeError. # Use 'EN' as fallback in both cases since we cannot reasonably detect the locale. return "en"
def get_locale(self): langname = self.get_uh_setting('Language') locale_code = LANGUAGENAMES.get_by_value(langname) if not langname == 'System default': return locale_code try: default_locale, default_encoding = locale.getdefaultlocale() return default_locale.split('_')[0] except (ValueError, AttributeError): # OS X sometimes returns 'UTF-8' as locale, which is a ValueError. # If no locale is set at all, the split will fail, which is an AttributeError. # Use 'EN' as fallback in both cases since we cannot reasonably detect the locale. return "en"
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_authors_per_file(input_po, regexp=LANG_RE, since='weblate-credits..', pushed_by='Weblate'): authors = subprocess.check_output([ 'git', 'log', since, '--committer', pushed_by, '--format=%an', input_po, ], stderr=subprocess.STDOUT) #TODO Clearly the above can never fail, ever. But what if it did? lang = regexp.search(input_po).groups()[0] for author in authors.decode('utf-8').split('\n'): if not author: continue if author in GLOBAL_AUTHORS: continue english_lang = LANGUAGENAMES.get_english(lang) language_authors[english_lang].add(author)
def _update_infos(self): """Fill in infos of selected scenario to label TODO document the 100 side effects""" scenario = self._gui.findChild(name="maplist").selected_item lang_list = self._gui.findChild(name="uni_langlist") selected_language = lang_list.selected_item lang_list.items = self._get_available_languages(scenario) lang_list.selected = 0 if selected_language in lang_list.items: lang_list.selected = lang_list.items.index(selected_language) cur_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item) translated_scenario = self._find_map_filename(scenario, cur_locale) if translated_scenario is None: translated_scenario = self._guess_suitable_default_locale(scenario) if translated_scenario is None: return self._update_scenario_translation_infos(translated_scenario)
def main(): # Main interface translation (old 'uh' project in pootle) for f in INTERFACE_TRANSLATIONS: update_from_template(f, INTERFACE_TEMPLATE) update_authors_per_file(f) # MP server message translation (old 'mp-server' project in pootle) for f in MP_SERVER_TRANSLATIONS: update_from_template(f, MP_SERVER_TEMPLATE) update_authors_per_file(f) # Glossary translation (old 'terminology' project in pootle) #for f in GLOSSARY_TRANSLATIONS: # update_from_template(f, GLOSSARY_TEMPLATE) # update_authors_per_file(f) # Scenario translation (old 'scenarios' project in pootle) for scenario, translations in SCENARIO_TRANSLATIONS.items(): for f in translations: update_from_template(f, SCENARIO_TEMPLATE[scenario]) update_authors_per_file(f, regexp=SCENARIO_LANG_RE) # Voices translation for f in VOICES_TRANSLATIONS: update_from_template(f, VOICES_TEMPLATE) update_authors_per_file(f) # Output data ready for AUTHORS.md copy/paste print('-- New translation contributors since last update:') sort_order = lambda (lang, _): LANGUAGENAMES.get_by_value(lang, english=True) for language, authors in sorted(language_authors.items(), key=sort_order): print('\n####', language) #TODO # The sorted() below will not correctly sort names containing non-ascii. # You'll need to rely on manual copy/paste and ordering anyways, so just # keep your eyes open a bit more than usual. for author in sorted(authors): print_ready = map(str.capitalize, author.split()) print('*', ' '.join(print_ready))
def main(): # Main interface translation (old 'uh' project in pootle) for f in INTERFACE_TRANSLATIONS: #update_from_template(f, INTERFACE_TEMPLATE) update_authors_per_file(f) # MP server message translation (old 'mp-server' project in pootle) for f in MP_SERVER_TRANSLATIONS: update_from_template(f, MP_SERVER_TEMPLATE) update_authors_per_file(f) # Glossary translation (old 'terminology' project in pootle) #for f in GLOSSARY_TRANSLATIONS: # update_from_template(f, GLOSSARY_TEMPLATE) # update_authors_per_file(f) # Scenario translation (old 'scenarios' project in pootle) for scenario, translations in SCENARIO_TRANSLATIONS.items(): for f in translations: update_from_template(f, SCENARIO_TEMPLATE[scenario]) update_authors_per_file(f, regexp=SCENARIO_LANG_RE) # Voices translation for f in VOICES_TRANSLATIONS: update_from_template(f, VOICES_TEMPLATE) update_authors_per_file(f) # Output data ready for AUTHORS.md copy/paste print '-- New translation contributors since last update:' sort_order = lambda (lang, _): LANGUAGENAMES.get_by_value(lang, english=True) for language, authors in sorted(language_authors.items(), key=sort_order): print '\n####', language #TODO # The sorted() below will not correctly sort names containing non-ascii. # You'll need to rely on manual copy/paste and ordering anyways, so just # keep your eyes open a bit more than usual. for author in sorted(authors): print_ready = map(str.capitalize, author.split()) print '*', ' '.join(print_ready)
def update_languages(self, data=None): """ Load/Change language of Unknown Horizons. Called on startup and when changing the language. data is used when changing the language in the settings menu. """ if data is None: data = self._setting.get(UH_MODULE, "Language") # get language key symbol = LANGUAGENAMES.get_by_value(data) if symbol != '': # non-default try: # NOTE about gettext fallback mechanism: # English is not shipped as .mo file, thus if English is # selected we use NullTranslations to get English output. fallback = (symbol == 'en') trans = gettext.translation('unknown-horizons', find_available_languages()[symbol], \ languages=[symbol], fallback=fallback) trans.install(unicode=True, names=['ngettext',]) except IOError: #xgettext:python-format print _("Configured language {lang} could not be loaded").format(lang=symbol) self._setting.set(UH_MODULE, "Language", LANGUAGENAMES['']) return self.update_languages() # recurse else: # default locale if platform.system() == "Windows": # win doesn't set the language variable by default os.environ[ 'LANGUAGE' ] = locale.getdefaultlocale()[0] gettext.install('unknown-horizons', 'content/lang', unicode=True, names=['ngettext',]) # update fonts fontdef = get_fontdef_for_locale(symbol) self.engine.pychan.loadFonts(fontdef) # dynamically reset all translations of active widgets update_all_translations()
def update_authors_per_file(input_po, regexp=LANG_RE, since='weblate-credits..', pushed_by='Weblate'): authors = subprocess.check_output([ 'git', 'shortlog', since, '--committer', pushed_by, '-sn', # Use 'sne' to include email (if that is ever needed) '--', input_po, ], stderr=subprocess.STDOUT) #TODO Clearly the above can never fail, ever. But what if it did? lang = regexp.search(input_po).groups()[0] for author_line in authors.split('\n'): if not author_line: continue author = JUST_NAME.search(author_line).groups()[0] if author in GLOBAL_AUTHORS: continue english_lang = LANGUAGENAMES.get_english(lang) language_authors[english_lang].add(author)
def _apply_Language(self, old, new): language = LANGUAGENAMES.get_by_value(new) change_language(language)
def _setup_settings(self, check_file_version=True): _user_config_file = os.path.join( os.getcwd(), PATHS.USER_CONFIG_FILE ) if check_file_version and os.path.exists(_user_config_file): # check if user settings file is the current one # NOTE: SimpleXMLSerializer can't handle relative paths, it fails silently # (although the doc states otherwise) - thus translate paths to absolute ones user_config_parser = SimpleXMLSerializer( _user_config_file ) user_settings_version = user_config_parser.get("meta", "SettingsVersion", -1) _template_config_file = os.path.join( os.getcwd(), PATHS.CONFIG_TEMPLATE_FILE ) template_config_parser = SimpleXMLSerializer( _template_config_file ) template_settings_version = template_config_parser.get("meta", "SettingsVersion") if template_settings_version > user_settings_version: # we have to update the file print 'Discovered old settings file, auto-upgrading: %s -> %s' % \ (user_settings_version, template_settings_version) # create settings so we have a list of all settings self._setup_settings(check_file_version=False) # save settings here entries = [] # need safe default value default_value = object() def update_value(modulename, entryname): # retrieve values from loaded settings file try: value = self._setting.get(modulename, entryname, default_value) except UnicodeEncodeError: # this can happen when unicode data is saved as str value = "default" if value is not default_value: entries.append( (modulename, entryname, value ) ) # collect values from known settings and unreferenced settings for modulename, module in self._setting.entries.iteritems(): for entryname in module.iterkeys(): update_value(modulename, entryname) for modulename, entry_list in self.UNREFERENCED_SETTINGS.iteritems(): for entryname in entry_list: update_value(modulename, entryname) # patch old values if user_settings_version <= 10: old_entries = entries entries = [] for i in old_entries: if i[0] == UH_MODULE and i[1] == "Language": entries.append( (i[0], i[1], LANGUAGENAMES.get_by_value(i[2])) ) else: entries.append(i) # write actual new file shutil.copy( PATHS.CONFIG_TEMPLATE_FILE, PATHS.USER_CONFIG_FILE ) user_config_parser = SimpleXMLSerializer( _user_config_file ) for modulename, entryname, value in entries: user_config_parser.set(modulename, entryname, value) user_config_parser.save() self._setting = SettingsDialog(app_name=UH_MODULE, settings_file=PATHS.USER_CONFIG_FILE, settings_gui_xml="settings.xml", changes_gui_xml="requirerestart.xml", default_settings_file=PATHS.CONFIG_TEMPLATE_FILE) self._setting_handler.add_settings()
def update_languages(self, data=None): if data is None: data = self._setting.get(UH_MODULE, "Language") language = LANGUAGENAMES.get_by_value(data) change_language(language)
def languagesort(item): return LANGUAGENAMES.get_by_value(item[0], english=True)
def _set_client_language(self): lang = LANGUAGENAMES.get_by_value( horizons.globals.fife.get_uh_setting("Language")) if lang: return self.set_props({'lang': lang})
def _on_Language_changed(self, old, new): language = LANGUAGENAMES.get_by_value(new) change_language(language)
def _setup_settings(self, check_file_version=True): # NOTE: SimpleXMLSerializer can't handle relative paths, it fails silently # (although the doc states otherwise) - thus translate paths to absolute ones _template_config_file = os.path.join(os.getcwd(), PATHS.CONFIG_TEMPLATE_FILE) template_config_parser = SimpleXMLSerializer(_template_config_file) template_settings_version = template_config_parser.get( "meta", "SettingsVersion") self._default_hotkeys = template_config_parser.getAllSettings( KEY_MODULE) _user_config_file = os.path.join(os.getcwd(), PATHS.USER_CONFIG_FILE) if check_file_version and os.path.exists(_user_config_file): # check if user settings file is the current one user_config_parser = SimpleXMLSerializer(_user_config_file) user_settings_version = user_config_parser.get( "meta", "SettingsVersion", -1) if template_settings_version > user_settings_version: # we have to update the file print 'Discovered old settings file, auto-upgrading: %s -> %s' % \ (user_settings_version, template_settings_version) # create settings so we have a list of all settings self._setup_settings(check_file_version=False) # save settings here entries = [] # need safe default value default_value = object() def update_value(modulename, entryname): # retrieve values from loaded settings file try: value = self._setting.get(modulename, entryname, default_value) except UnicodeEncodeError: # this can happen when unicode data is saved as str value = "default" if value is not default_value: entries.append((modulename, entryname, value)) # collect values from known settings and unreferenced settings for modulename, module in self._setting.entries.iteritems(): for entryname in module.iterkeys(): update_value(modulename, entryname) for modulename, entry_list in self.UNREFERENCED_SETTINGS.iteritems( ): for entryname in entry_list: update_value(modulename, entryname) # patch old values if user_settings_version <= 10: old_entries = entries entries = [] for i in old_entries: if i[0] == UH_MODULE and i[1] == "Language": entries.append( (i[0], i[1], LANGUAGENAMES.get_by_value(i[2]))) else: entries.append(i) # write actual new file shutil.copy(PATHS.CONFIG_TEMPLATE_FILE, PATHS.USER_CONFIG_FILE) user_config_parser = SimpleXMLSerializer(_user_config_file) for modulename, entryname, value in entries: user_config_parser.set(modulename, entryname, value) user_config_parser.save() self._setting = SettingsDialog( app_name=UH_MODULE, settings_file=PATHS.USER_CONFIG_FILE, settings_gui_xml="settings.xml", changes_gui_xml="requirerestart.xml", default_settings_file=PATHS.CONFIG_TEMPLATE_FILE) self._setting_handler.add_settings()
def set_unknownhorizons_Language(self, value): return LANGUAGENAMES.get_by_value(value)
def apply(self): data = self.get(SETTINGS.UH_MODULE, "Language") language = LANGUAGENAMES.get_by_value(data) change_language(language)
def _set_client_language(self): lang = LANGUAGENAMES.get_by_value(horizons.globals.fife.get_uh_setting("Language")) if lang: return self.set_props({'lang': lang})