[gnome-tweak-tool] Use Python class-based gettext



commit 2818d1efd77cc6aca04434ff24ef16e374e61a5c
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Sep 9 16:04:31 2012 +0200

    Use Python class-based gettext
    
    Python's gettext does not use gettext from the glibc, so the function
    _ provided by gettext.install does not care about textdomain() or bindtextdomain().
    Instead, it wants a domain and localedir explicitly, as well as any
    extra function that should be installed.
    This fixes the translations for all strings provided by gnome-tweak-tool.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683630

 gnome-tweak-tool     |    4 +---
 gtweak/gsettings.py  |   12 +++++++-----
 gtweak/tweakmodel.py |    3 +--
 3 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gnome-tweak-tool b/gnome-tweak-tool
index c377b01..6104959 100755
--- a/gnome-tweak-tool
+++ b/gnome-tweak-tool
@@ -69,9 +69,7 @@ if __name__ == '__main__':
     logging.basicConfig(format="%(levelname)-8s: %(message)s", level=level)
 
     locale.setlocale(locale.LC_ALL, None)
-    gettext.bindtextdomain(gtweak.APP_NAME, LOCALE_DIR)
-    gettext.textdomain(gtweak.APP_NAME)
-    gettext.install(gtweak.APP_NAME)
+    gettext.install(gtweak.APP_NAME, LOCALE_DIR, names=('gettext', 'ngettext'))
 
     from gtweak.mainwindow import MainWindow
     MainWindow()
diff --git a/gtweak/gsettings.py b/gtweak/gsettings.py
index c87cb84..5403b30 100644
--- a/gtweak/gsettings.py
+++ b/gtweak/gsettings.py
@@ -51,13 +51,15 @@ class _GSettingsSchema:
             if global_gettext_domain:
                 # We can't know where the schema owner was installed, let's assume it's
                 # the same prefix as ours
-                gettext.bindtextdomain(global_gettext_domain, gtweak.LOCALE_DIR)
+                global_translation = gettext.translation(global_gettext_domain, gtweak.LOCALE_DIR)
+            else:
+                global_translation = gettext.NullTranslations()
             for schema in dom.getElementsByTagName("schema"):
                 gettext_domain = schema.getAttribute('gettext-domain')
                 if gettext_domain:
-                    gettext.bindtextdomain(gettext_domain, gtweak.LOCALE_DIR)
+                    translation = gettext.translation(gettext_domain, gtweak.LOCALE_DIR)
                 else:
-                    gettext_domain = global_gettext_domain
+                    translation = global_translation
                 if schema_name == schema.getAttribute("id"):
                     for key in schema.getElementsByTagName("key"):
                         #summary is compulsory, description is optional
@@ -72,8 +74,8 @@ class _GSettingsSchema:
                         except:
                             description = ""
                         self._schema[key.getAttribute("name")] = {
-                                "summary"       :   gettext.dgettext(gettext_domain, summary),
-                                "description"   :   gettext.dgettext(gettext_domain, description)
+                                "summary"       :   translation.gettext(summary),
+                                "description"   :   translation.gettext(description)
                         }
         except:
             logging.critical("Error parsing schema %s (%s)" % (schema_name, schema_path), exc_info=True)
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index d1b0662..4661ff0 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -18,7 +18,6 @@
 import logging
 import glob
 import os.path
-import gettext
 
 import gtweak
 
@@ -159,7 +158,7 @@ class TweakModel(Gtk.ListStore):
             LOG.critical("Tweak group named: %s already exists" % tweakgroup.name)
             return
 
-        _iter = self.append([gettext.gettext(tweakgroup.name), tweakgroup])
+        _iter = self.append([gettext(tweakgroup.name), tweakgroup])
         self._tweak_group_names[tweakgroup.name] = tweakgroup
         self._tweak_group_iters[tweakgroup.name] = _iter
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]