Fix GtkBuilder translation

Fixes #9277
This commit is contained in:
Philipp Hörist 2018-08-06 17:14:07 +02:00
parent 2fd7187d16
commit 2e53f47da8
2 changed files with 23 additions and 30 deletions

View File

@ -51,34 +51,30 @@ def load_icon(icon_name, widget, size=16, pixbuf=False,
def get_builder(file_name, widget=None):
file_path = os.path.join(configpaths.get('GUI'), file_name)
builder = _translate(file_path, widget)
builder = Gtk.Builder()
builder.set_translation_domain(i18n.DOMAIN)
return builder
def _translate(gui_file, widget):
"""
This is a workaround for non working translation on Windows
"""
if sys.platform == "win32":
tree = ET.parse(gui_file)
# This is a workaround for non working translation on Windows
tree = ET.parse(file_path)
for node in tree.iter():
if 'translatable' in node.attrib:
node.text = _(node.text)
xml_text = ET.tostring(tree.getroot(),
encoding='unicode',
method='xml')
if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_string(xml_text, [widget])
return builder
return Gtk.Builder.new_from_string(xml_text, -1)
else:
builder.add_from_string(xml_text, -1)
else:
if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_file(gui_file, [widget])
return builder
return Gtk.Builder.new_from_file(gui_file)
builder.add_objects_from_file(file_path, [widget])
else:
builder.add_from_file(file_path)
return builder
def get_iconset_name_for(name):

View File

@ -127,33 +127,30 @@ def get_image_button(icon_name, tooltip, toggle=False):
def get_gtk_builder(file_name, widget=None):
file_path = os.path.join(configpaths.get('GUI'), file_name)
builder = _translate(file_path, widget)
builder.set_translation_domain(i18n.DOMAIN)
return builder
def _translate(gui_file, widget):
"""
This is a workaround for non working translation on Windows
"""
builder = Gtk.Builder()
builder.set_translation_domain(i18n.DOMAIN)
if sys.platform == "win32":
tree = ET.parse(gui_file)
# This is a workaround for non working translation on Windows
tree = ET.parse(file_path)
for node in tree.iter():
if 'translatable' in node.attrib:
node.text = _(node.text)
xml_text = ET.tostring(tree.getroot(),
encoding='unicode',
method='xml')
if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_string(xml_text, [widget])
return builder
return Gtk.Builder.new_from_string(xml_text, -1)
else:
builder.add_from_string(xml_text, -1)
else:
if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_file(gui_file, [widget])
return builder
return Gtk.Builder.new_from_file(gui_file)
builder.add_objects_from_file(file_path, [widget])
else:
builder.add_from_file(file_path)
return builder
def get_completion_liststore(entry):
"""