Fix translation on Windows

Fixes #8658
This commit is contained in:
Philipp Hörist 2018-06-23 17:02:23 +02:00
parent 7e1afd69df
commit 23c302ca70
3 changed files with 25 additions and 50 deletions

View File

@ -144,10 +144,8 @@ class GajimApplication(Gtk.Application):
# Set Application Menu
app.app = self
path = os.path.join(configpaths.get('GUI'), 'application_menu.ui')
builder = Gtk.Builder()
builder.set_translation_domain(i18n.DOMAIN)
builder.add_from_file(path)
from gajim import gtkgui_helpers
builder = gtkgui_helpers.get_gtk_builder('application_menu.ui')
menubar = builder.get_object("menubar")
appmenu = builder.get_object("appmenu")
if app.prefers_app_menu():

View File

@ -40,7 +40,6 @@ def initialize():
except locale.Error as error:
print(error)
# initialize_win_translation() broken
initialize_lang()
set_i18n_env()
@ -75,8 +74,7 @@ def initialize_lang():
def get_locale_dir():
if os.name == 'nt':
return "../po"
return None
# try to find domain in localedir
path = gettext.find(DOMAIN)
if path:
@ -96,44 +94,6 @@ def get_locale_dir():
return localedir
def initialize_win_translation():
# broken for now
return
if os.name != 'nt':
return
# needed for docutils
# sys.path.append('.')
APP = 'gajim'
DIR = '../po'
lang = locale.getdefaultlocale()[0]
os.environ['LANG'] = lang
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
gettext.install(APP, DIR)
# This is for Windows translation which is currently not
# working on GTK 3.18.9
# locale.setlocale(locale.LC_ALL, '')
# import ctypes
# import ctypes.util
# libintl_path = ctypes.util.find_library('intl')
# if libintl_path == None:
# local_intl = os.path.join('gtk', 'bin', 'intl.dll')
# if os.path.exists(local_intl):
# libintl_path = local_intl
# if libintl_path == None:
# raise ImportError('intl.dll library not found')
# libintl = ctypes.cdll.LoadLibrary(libintl_path)
# libintl.bindtextdomain(APP, DIR)
# libintl.bind_textdomain_codeset(APP, 'UTF-8')
# plugins_locale_dir = os.path.join(common.configpaths[
# 'PLUGINS_USER'], 'locale').encode(locale.getpreferredencoding())
# libintl.bindtextdomain('gajim_plugins', plugins_locale_dir)
# libintl.bind_textdomain_codeset('gajim_plugins', 'UTF-8')
def initialize_direction_mark():
from gi.repository import Gtk

View File

@ -38,6 +38,7 @@ import cairo
import os
import sys
import math
import xml.etree.ElementTree as ET
try:
from PIL import Image
except:
@ -125,14 +126,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 = Gtk.Builder()
builder = _translate(file_path, widget)
builder.set_translation_domain(i18n.DOMAIN)
if widget:
builder.add_objects_from_file(file_path, [widget])
else:
builder.add_from_file(file_path)
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)
for node in tree.iter():
if 'translatable' in node.attrib:
node.text = _(node.text)
xml_text = ET.tostring(tree.getroot(),
encoding='unicode',
method='xml')
return Gtk.Builder.new_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)
def get_completion_liststore(entry):
"""
Create a completion model for entry widget completion list consists of