[hamster-applet] moved all the i18n into single place



commit d475bff448c3c8d256f9e6340aeae836c8449b27
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue May 25 23:27:11 2010 +0100

    moved all the i18n into single place

 src/hamster-applet     |   19 ++++++-------------
 src/hamster-client     |   13 ++-----------
 src/hamster-service    |   11 ++---------
 src/hamster-standalone |   12 ++----------
 src/hamster/stuff.py   |   14 +++++++++++++-
 5 files changed, 25 insertions(+), 44 deletions(-)
---
diff --git a/src/hamster-applet b/src/hamster-applet
index 54244c2..f303668 100755
--- a/src/hamster-applet
+++ b/src/hamster-applet
@@ -91,17 +91,10 @@ if __name__ == "__main__":
                             format = log_format)
 
     try:
-        from hamster import defs
-        from hamster.configuration import runtime, dialogs
-
-        # Setup i18n
-        locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
-        for module in (gettext, locale):
-            module.bindtextdomain('hamster-applet', locale_dir)
-            module.textdomain('hamster-applet')
+        from hamster import stuff
+        stuff.setup_i18n()
 
-            if hasattr(module, 'bind_textdomain_codeset'):
-                module.bind_textdomain_codeset('hamster-applet','UTF-8')
+        from hamster.configuration import runtime, dialogs
 
         gtk.window_set_default_icon_name("hamster-applet")
 
@@ -119,7 +112,7 @@ if __name__ == "__main__":
                 dialogs.prefs.show()
 
             else: #default to main applet
-                gnome.init(defs.PACKAGE, defs.VERSION)
+                gnome.init("hamster-applet", runtime.version)
 
                 app = gtk.Window(gtk.WINDOW_TOPLEVEL)
                 app.set_title(_(u"Time Tracker"))
@@ -134,8 +127,8 @@ if __name__ == "__main__":
             gnomeapplet.bonobo_factory(
                 "OAFIID:Hamster_Applet_Factory",
                 gnomeapplet.Applet.__gtype__,
-                defs.PACKAGE,
-                defs.VERSION,
+                "hamster-applet",
+                runtime.version,
                 applet_factory)
     except:
         # make sure the error appears somewhere
diff --git a/src/hamster-client b/src/hamster-client
index e55c22a..4ea01c0 100755
--- a/src/hamster-client
+++ b/src/hamster-client
@@ -212,17 +212,8 @@ def fact_dict(fact_data, with_date):
 
 
 if __name__ == '__main__':
-    # Setup i18n
-    gettext.install("hamster-applet", unicode=True)
-    locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
-    for module in (gettext, locale):
-        module.bindtextdomain('hamster-applet', locale_dir)
-        module.textdomain('hamster-applet')
-
-        if hasattr(module, 'bind_textdomain_codeset'):
-            module.bind_textdomain_codeset('hamster-applet','UTF-8')
-
-
+    from hamster import stuff
+    stuff.setup_i18n()
 
     usage = _(
 """Client for controlling the hamster-applet. Usage:
diff --git a/src/hamster-service b/src/hamster-service
index 3dde0ce..571fa52 100755
--- a/src/hamster-service
+++ b/src/hamster-service
@@ -20,15 +20,8 @@ SOURCE_DIR = LAUNCH_DIR
 STORAGE = os.path.join(SOURCE_DIR, "hamster", "storage.py")
 
 if __name__ == '__main__':
-    # Setup i18n
-    gettext.install("hamster-applet", unicode=True)
-    locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
-    for module in (gettext, locale):
-        module.bindtextdomain('hamster-applet', locale_dir)
-        module.textdomain('hamster-applet')
-
-        if hasattr(module, 'bind_textdomain_codeset'):
-            module.bind_textdomain_codeset('hamster-applet','UTF-8')
+    from hamster import stuff
+    stuff.setup_i18n()
 
     # adjust path if running from source
     if os.path.exists(SOURCE_DIR):
diff --git a/src/hamster-standalone b/src/hamster-standalone
index 55b7c06..909a510 100755
--- a/src/hamster-standalone
+++ b/src/hamster-standalone
@@ -467,16 +467,8 @@ class ProjectHamster(object):
         gtk.main_quit()
 
 if __name__ == "__main__":
-    from hamster import defs
-
-    # Setup i18n
-    locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
-    for module in (gettext, locale):
-        module.bindtextdomain('hamster-applet', locale_dir)
-        module.textdomain('hamster-applet')
-
-        if hasattr(module, 'bind_textdomain_codeset'):
-            module.bind_textdomain_codeset('hamster-applet','UTF-8')
+    from hamster import stuff
+    stuff.setup_i18n()
 
     gtk.gdk.threads_init()
     app = ProjectHamster()
diff --git a/src/hamster/stuff.py b/src/hamster/stuff.py
index 21ea0c8..80b48ef 100644
--- a/src/hamster/stuff.py
+++ b/src/hamster/stuff.py
@@ -30,9 +30,21 @@ from itertools import groupby
 import datetime as dt
 import time
 import re
-import locale
+import gettext, locale
 import os
 
+def setup_i18n():
+    # Setup i18n
+    from configuration import runtime
+    locale_dir = os.path.abspath(os.path.join(runtime.data_dir, "..", "locale"))
+    for module in (gettext, locale):
+        module.bindtextdomain('hamster-applet', locale_dir)
+        module.textdomain('hamster-applet')
+
+        if hasattr(module, 'bind_textdomain_codeset'):
+            module.bind_textdomain_codeset('hamster-applet','UTF-8')
+
+
 def format_duration(minutes, human = True):
     """formats duration in a human readable format.
     accepts either minutes or timedelta"""



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