本文整理汇总了Python中horizons.constants.LANGUAGENAMES.get_by_value方法的典型用法代码示例。如果您正苦于以下问题:Python LANGUAGENAMES.get_by_value方法的具体用法?Python LANGUAGENAMES.get_by_value怎么用?Python LANGUAGENAMES.get_by_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.constants.LANGUAGENAMES
的用法示例。
在下文中一共展示了LANGUAGENAMES.get_by_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _find_map_filename
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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
示例2: _update_infos
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例3: set
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例4: _on_Language_changed
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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 = ''
示例5: get_locale
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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"
示例6: _update_infos
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例7: _update_infos
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例8: main
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例9: update_languages
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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()
示例10: update_languages
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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)
示例11: languagesort
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
def languagesort(item):
return LANGUAGENAMES.get_by_value(item[0], english=True)
示例12: apply
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
def apply(self):
data = self.get(SETTINGS.UH_MODULE, "Language")
language = LANGUAGENAMES.get_by_value(data)
change_language(language)
示例13: set_unknownhorizons_Language
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
def set_unknownhorizons_Language(self, value):
return LANGUAGENAMES.get_by_value(value)
示例14: _set_client_language
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
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})
示例15: _on_Language_changed
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import get_by_value [as 别名]
def _on_Language_changed(self, old, new):
language = LANGUAGENAMES.get_by_value(new)
change_language(language)