Commit 2e53f47d authored by Philipp Hörist's avatar Philipp Hörist

Fix GtkBuilder translation

Fixes #9277
parent 2fd7187d
......@@ -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.set_translation_domain(i18n.DOMAIN)
return builder
builder = Gtk.Builder()
builder.set_translation_domain(i18n.DOMAIN)
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):
......
......@@ -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 = 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_completion_liststore(entry):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment