Пример #1
0
	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
0
    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()
Пример #3
0
	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()
Пример #4
0
	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()