From cc655348ebb091683625dcfe4d7d0039f452b4ef Mon Sep 17 00:00:00 2001 From: Andy Holmes Date: Fri, 6 Dec 2019 12:11:40 -0800 Subject: [PATCH] Nautilus Extension: fix gettext usage Apparently the way we did this in GSConnect never actually worked, it just took years for someone to report it. Since this extension is derived from GSConnect's it's likely that's the case here, too. This is the appropriate way to use gettext according to the Python3 documentation. --- nautilus-extension/kdeconnect-share.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nautilus-extension/kdeconnect-share.py b/nautilus-extension/kdeconnect-share.py index d86580a5e..82e002475 100644 --- a/nautilus-extension/kdeconnect-share.py +++ b/nautilus-extension/kdeconnect-share.py @@ -29,12 +29,17 @@ __app_disp_name__ = "Share files to your phone via KDE Connect" __website__ = "https://community.kde.org/KDEConnect" import gettext -import locale from functools import partial from gi.repository import Nautilus, Gio, GLib, GObject -_ = gettext.gettext +try: + i18n = gettext.translation('kdeconnect-nautilus-extension') + _ = i18n.gettext +except (IOError, OSError) as e: + print('kdeconnect-nautilus: {0}'.format(e.strerr)) + i18n = gettext.translation('kdeconnect-nautilus-extension', fallback=True) + _ = i18n.gettext class KdeConnectShareExtension(GObject.GObject, Nautilus.MenuProvider): """A context menu for sending files via KDE Connect.""" @@ -55,12 +60,6 @@ class KdeConnectShareExtension(GObject.GObject, Nautilus.MenuProvider): self.devices = {} - try: - locale.setlocale(locale.LC_ALL, '') - gettext.bindtextdomain('kdeconnect-nautilus-extension') - except Exception as e: - print(e) - self.dbus = Gio.DBusProxy.new_for_bus_sync( Gio.BusType.SESSION, Gio.DBusProxyFlags.NONE,