Exemplo n.º 1
0
def update_all_translations():
    """Update the translations in every active widget"""
    global translated_widgets
    guitranslations.set_translations()
    objecttranslations.set_translations()
    for (filename, widget) in translated_widgets.iteritems():
        widget = widget()  # resolve weakref
        if not widget:
            continue
        all_widgets = guitranslations.text_translations.get(filename, {})
        for (element_name, attribute), translation in all_widgets.iteritems():
            element = widget.findChild(name=element_name)
            replace_attribute(element, attribute, translation)
        widget.adaptLayout()
Exemplo n.º 2
0
def update_all_translations():
	"""Update the translations in every active widget"""
	global translated_widgets
	guitranslations.set_translations()
	objecttranslations.set_translations()
	for (filename, widget) in translated_widgets.iteritems():
		widget = widget() # resolve weakref
		if not widget:
			continue
		all_widgets = guitranslations.text_translations.get(filename, {})
		for (element_name, attribute), translation in all_widgets.iteritems():
			element = widget.findChild(name=element_name)
			replace_attribute(element, attribute, translation)
		widget.adaptLayout()
Exemplo n.º 3
0
def update_all_translations():
    set_translations()
    global translated_widgets
    for i in translated_widgets.iteritems():
        for j in guitranslations.text_translations.get(i[0], {}).iteritems():
            try:
                widget = i[1].findChild(name=j[0])
                if isinstance(widget, _Tooltip):
                    widget.tooltip = j[1]
                else:
                    widget.text = j[1]
                i[1].adaptLayout()
            except AttributeError, e:
                print e
                print i, ' in ', i[0]
Exemplo n.º 4
0
def update_all_translations():
	set_translations()
	global translated_widgets
	for i in translated_widgets.iteritems():
		for j in guitranslations.text_translations.get(i[0],{}).iteritems():
			try:
				widget = i[1].findChild(name=j[0])
				if isinstance(widget, _Tooltip):
					widget.tooltip = j[1]
				else:
					widget.text = j[1]
				i[1].adaptLayout()
			except AttributeError, e:
				print e
				print i, ' in ', i[0]
Exemplo n.º 5
0
def update_all_translations():
	"""Update the translations in every active widget"""
	from horizons.gui.gui import build_help_strings
	global translated_widgets
	guitranslations.set_translations()
	objecttranslations.set_translations()
	for (filename, widget) in translated_widgets.iteritems():
		widget = widget() # resolve weakref
		if not widget:
			continue
		for (element_name, attribute), translation in guitranslations.text_translations.get(filename,{}).iteritems():
			element = widget.findChild(name=element_name)
			replace_attribute(element, attribute, translation)
		if filename == 'help.xml':
			build_help_strings(widget)
		widget.adaptLayout()
Exemplo n.º 6
0
def update_all_translations():
    set_translations()
    global translated_widgets
    for i in translated_widgets.iteritems():
        for j in guitranslations.text_translations.get(i[0], {}).iteritems():
            try:
                widget = i[1].findChild(name=j[0])
                #TODO presumably doesn't work with TooltipLabels, see above
                if hasattr(widget, 'tooltip'):
                    widget.tooltip = j[1]
                else:
                    widget.text = j[1]
                i[1].adaptLayout()
            except AttributeError, e:
                print e
                print i, ' in ', i[0]
Exemplo n.º 7
0
def update_all_translations():
	set_translations()
	global translated_widgets
	for i in translated_widgets.iteritems():
		for j in guitranslations.text_translations.get(i[0],{}).iteritems():
			try:
				widget = i[1].findChild(name=j[0])
				#TODO presumably doesn't work with TooltipLabels, see above
				if hasattr(widget, 'tooltip'):
					widget.tooltip = j[1]
				else:
					widget.text = j[1]
				i[1].adaptLayout()
			except AttributeError, e:
				print e
				print i, ' in ', i[0]
Exemplo n.º 8
0
def update_all_translations():
    """Update the translations in every active widget"""
    import horizons.main
    global translated_widgets
    guitranslations.set_translations()
    objecttranslations.set_translations()
    for (filename, widget) in translated_widgets.iteritems():
        widget = widget()  # resolve weakref
        if not widget:
            continue
        all_widgets = guitranslations.text_translations.get(filename, {})
        for (element_name, attribute), translation in all_widgets.iteritems():
            element = widget.findChild(name=element_name)
            replace_attribute(element, attribute, translation)
        if filename == 'help.xml':
            horizons.main._modules.gui.build_help_strings()
        widget.adaptLayout()
Exemplo n.º 9
0
def update_all_translations():
	"""Update the translations in every active widget"""
	global translated_widgets
	set_translations()
	for (filename, widget) in translated_widgets.iteritems():
		widget = widget() # resolve weakref
		if not widget:
			continue
		for element_name, translation in guitranslations.text_translations.get(filename,{}).iteritems():
			try:
				w = widget.findChild(name=element_name)
				#TODO presumably doesn't work with TooltipLabels, see above
				if hasattr(w, 'tooltip'):
					w.tooltip = translation
				else:
					w.text = translation
				widget.adaptLayout()
			except AttributeError, e:
				print e
				print filename, widget
Exemplo n.º 10
0
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ###################################################

import logging
from horizons.i18n.guitranslations import set_translations, text_translations
import horizons.main
from horizons.gui.widgets.tooltip import _Tooltip

from fife.extensions import pychan
from os.path import basename
import os

log = logging.getLogger("i18n")

# init translations
set_translations()

# save translated widgets
translated_widgets = {}

# create dictionary with all gui .xml files
xml_files = {}
for root, dirs, files in os.walk('content/gui'):
    files = filter(lambda s: s.split('.')[-1] in ('.xml'), files)
    if files:
        for i in files:
            if i not in xml_files.keys():
                xml_files[i] = root + '/' + i
            else:
                print 'Another file by the name %s already exists. Please use unique names!' % i
"""
Exemplo n.º 11
0
import platform
import gettext
import os
import logging
import locale
import weakref

from horizons.constants import LANGUAGENAMES
from horizons.i18n import objecttranslations, guitranslations
from horizons.i18n.utils import get_fontdef_for_locale, find_available_languages

log = logging.getLogger("i18n")

# init translations
guitranslations.set_translations()
objecttranslations.set_translations()

# save translated widgets
translated_widgets = {}

def translate_widget(untranslated, filename):
	"""
	Load widget translations from guitranslations.py file.
	Its entries look like {element_name: (attribute, translation)}.
	The translation is not applied to inactive widgets.
	Check update_all_translations for the application.
	"""
	global translated_widgets
	if filename in guitranslations.text_translations:
		for entry in guitranslations.text_translations[filename].iteritems():
Exemplo n.º 12
0
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ###################################################

import logging
from horizons.i18n.guitranslations import set_translations, text_translations
import horizons.main
from  horizons.gui.widgets.tooltip import _Tooltip

from fife.extensions import pychan
from os.path import basename
import os

log = logging.getLogger("i18n")

# init translations
set_translations()

# save translated widgets
translated_widgets = {}

# create dictionary with all gui .xml files
xml_files = {}
for root, dirs, files in os.walk('content/gui'):
	files = filter(lambda s: s.split('.')[-1] in ('.xml'), files)
	if files:
		for i in files:
			if i not in xml_files.keys():
				xml_files[i] = root + '/' + i
			else:
				print 'Another file by the name %s already exists. Please use unique names!' % i