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, ...@@ -51,34 +51,30 @@ def load_icon(icon_name, widget, size=16, pixbuf=False,
def get_builder(file_name, widget=None): def get_builder(file_name, widget=None):
file_path = os.path.join(configpaths.get('GUI'), file_name) 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": 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(): for node in tree.iter():
if 'translatable' in node.attrib: if 'translatable' in node.attrib:
node.text = _(node.text) node.text = _(node.text)
xml_text = ET.tostring(tree.getroot(), xml_text = ET.tostring(tree.getroot(),
encoding='unicode', encoding='unicode',
method='xml') method='xml')
if widget is not None: if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_string(xml_text, [widget]) builder.add_objects_from_string(xml_text, [widget])
return builder else:
return Gtk.Builder.new_from_string(xml_text, -1) builder.add_from_string(xml_text, -1)
else: else:
if widget is not None: if widget is not None:
builder = Gtk.Builder() builder.add_objects_from_file(file_path, [widget])
builder.add_objects_from_file(gui_file, [widget]) else:
return builder builder.add_from_file(file_path)
return Gtk.Builder.new_from_file(gui_file) return builder
def get_iconset_name_for(name): def get_iconset_name_for(name):
......
...@@ -127,33 +127,30 @@ def get_image_button(icon_name, tooltip, toggle=False): ...@@ -127,33 +127,30 @@ def get_image_button(icon_name, tooltip, toggle=False):
def get_gtk_builder(file_name, widget=None): def get_gtk_builder(file_name, widget=None):
file_path = os.path.join(configpaths.get('GUI'), file_name) file_path = os.path.join(configpaths.get('GUI'), file_name)
builder = _translate(file_path, widget)
builder = Gtk.Builder()
builder.set_translation_domain(i18n.DOMAIN) 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": 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(): for node in tree.iter():
if 'translatable' in node.attrib: if 'translatable' in node.attrib:
node.text = _(node.text) node.text = _(node.text)
xml_text = ET.tostring(tree.getroot(), xml_text = ET.tostring(tree.getroot(),
encoding='unicode', encoding='unicode',
method='xml') method='xml')
if widget is not None: if widget is not None:
builder = Gtk.Builder()
builder.add_objects_from_string(xml_text, [widget]) builder.add_objects_from_string(xml_text, [widget])
return builder else:
return Gtk.Builder.new_from_string(xml_text, -1) builder.add_from_string(xml_text, -1)
else: else:
if widget is not None: if widget is not None:
builder = Gtk.Builder() builder.add_objects_from_file(file_path, [widget])
builder.add_objects_from_file(gui_file, [widget]) else:
return builder builder.add_from_file(file_path)
return Gtk.Builder.new_from_file(gui_file) return builder
def get_completion_liststore(entry): 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