本文整理汇总了Python中horizons.constants.LANGUAGENAMES.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python LANGUAGENAMES.iteritems方法的具体用法?Python LANGUAGENAMES.iteritems怎么用?Python LANGUAGENAMES.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.constants.LANGUAGENAMES
的用法示例。
在下文中一共展示了LANGUAGENAMES.iteritems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_languages
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import iteritems [as 别名]
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()
示例2: update_languages
# 需要导入模块: from horizons.constants import LANGUAGENAMES [as 别名]
# 或者: from horizons.constants.LANGUAGENAMES import iteritems [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")
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()