当前位置: 首页>>代码示例>>Python>>正文


Python LANGUAGENAMES.iteritems方法代码示例

本文整理汇总了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()
开发者ID:carnivoro,项目名称:unknown-horizons,代码行数:32,代码来源:engine.py

示例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()
开发者ID:mitfik,项目名称:unknown-horizons,代码行数:55,代码来源:engine.py


注:本文中的horizons.constants.LANGUAGENAMES.iteritems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。