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


Python constants.LANGUAGENAMES类代码示例

本文整理汇总了Python中horizons.constants.LANGUAGENAMES的典型用法代码示例。如果您正苦于以下问题:Python LANGUAGENAMES类的具体用法?Python LANGUAGENAMES怎么用?Python LANGUAGENAMES使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LANGUAGENAMES类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _find_map_filename

						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
开发者ID:MasterofJOKers,项目名称:unknown-horizons,代码行数:25,代码来源:singleplayermenu.py

示例2: _update_infos

	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)
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:28,代码来源:singleplayermenu.py

示例3: get_locale

	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]
开发者ID:court-jus,项目名称:unknown-horizons,代码行数:7,代码来源:engine.py

示例4: set

	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)
开发者ID:Antagonym,项目名称:unknown-horizons,代码行数:7,代码来源:settingsdialog.py

示例5: update_languages

	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,代码行数:30,代码来源:engine.py

示例6: get_locale

	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"
开发者ID:perher,项目名称:unknown-horizons,代码行数:10,代码来源:engine.py

示例7: update_languages

	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,代码行数:53,代码来源:engine.py

示例8: _on_Language_changed

	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 = ''
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:13,代码来源:settings.py

示例9: get_locale

	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"
开发者ID:DanielStephens,项目名称:unknown-horizons,代码行数:13,代码来源:engine.py

示例10: get_locale

 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"
开发者ID:unknown-horizons,项目名称:unknown-horizons,代码行数:13,代码来源:engine.py

示例11: _update_infos

	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)
开发者ID:ThePawnBreak,项目名称:unknown-horizons,代码行数:49,代码来源:singleplayermenu.py

示例12: update_authors_per_file

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)
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:20,代码来源:update_translations.py

示例13: _update_infos

	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)
开发者ID:Rareson,项目名称:unknown-horizons,代码行数:21,代码来源:singleplayermenu.py

示例14: update_languages

	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()
开发者ID:aviler,项目名称:unknown-horizons,代码行数:39,代码来源:settingshandler.py

示例15: main

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)
开发者ID:Octavianuspg,项目名称:unknown-horizons,代码行数:39,代码来源:update_translations.py


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