1. Vladimir Kolev
  2. gtkPyglot

Commits

Vladimir Kolev  committed 9507023

Added internationalisation support

  • Participants
  • Parent commits 512a876
  • Branches default

Comments (0)

Files changed (1)

File gtkpyglot.py

View file
 import urllib
 import webbrowser
 import simplejson
+import locale
+import gettext
 from configobj import ConfigObj
 from pysqlite2 import dbapi2 as sqlite3
 
 GOOGLE_URL = "http://ajax.googleapis.com/ajax/services/language/translate"
 
 # Preconfigurations
+# Localisation
+APP = 'gtkpyglot'
+DIR = './locale'
+locale.setlocale(locale.LC_ALL, '')
+locale.bindtextdomain(APP, DIR)
+gettext.bindtextdomain(APP, DIR)
+gettext.textdomain(APP)
+_ = gettext.gettext
+gettext.install(APP, DIR)
 
 # Server information
 server = xmlrpclib.Server(SERVER_URL)
         
         def __init__(self):
                 builder = gtk.Builder()
+                builder.set_translation_domain(APP)
                 builder.add_from_file("%sdata/main-gui.ui" % cur_path)
                 builder.connect_signals({
                         "on_window1_destroy" : gtk.main_quit,
 
                 # Show the statistics in the statusbar
                 self.label_langs = builder.get_object("label1")
-                self.label_langs.set_markup("<b>Languages: </b> %s" % stats['total_languages'])
+                self.label_langs.set_markup(_("<b>Languages: </b> %s") % stats['total_languages'])
                 self.label_packs = builder.get_object("label2")
-                self.label_packs.set_markup("<b>Packages: </b> %s" % stats['total_packages'])
+                self.label_packs.set_markup(_("<b>Packages: </b> %s") % stats['total_packages'])
                 self.label_trans = builder.get_object("label3")
-                self.label_trans.set_markup("<b>Translations: </b> %s" % stats['total_translations'])
+                self.label_trans.set_markup(_("<b>Translations: </b> %s") % stats['total_translations'])
 
                 # Prepare the table for the results
                 self.store = gtk.ListStore(str, str, str, str)
 
         def create_columns(self, treeView):
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Translation", rendererText, text=0)
+                column = gtk.TreeViewColumn(_("Translation"), rendererText, text=0)
                 column.set_fixed_width(310)
                 column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
                 column.set_resizable(True)
                 treeView.append_column(column)
 
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Original", rendererText, text=1)
+                column = gtk.TreeViewColumn(_("Original"), rendererText, text=1)
                 column.set_fixed_width(200)
                 column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
                 column.set_resizable(True)
                 treeView.append_column(column)
 
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Last update", rendererText, text=2)
+                column = gtk.TreeViewColumn(_("Last update"), rendererText, text=2)
                 column.set_sort_column_id(1)
                 treeView.append_column(column)
 
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Standard", rendererText, text=3)
+                column = gtk.TreeViewColumn(_("Standard"), rendererText, text=3)
                 column.set_sort_column_id(2)
                 treeView.append_column(column)
 
                 if(searchterm == ""):
                         dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                                   gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
-                                                  "Nothing to search for...")
+                                                  _("Nothing to search for..."))
                         dialog.run()
                         dialog.destroy()
                 else:
                         if not translations:
                                 resdialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                                              gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
-                                                              "Sorry no results for: %s" % searchterm)
+                                                              _("Sorry no results for: %s") % searchterm)
                                 resdialog.run()
                                 resdialog.destroy()
                         else:
                                 self.store.clear()
                                 for trans in translations:
                                         self.store.append(['%s' % trans['translation'],
-                                                           'None',
+                                                           _('None'),
                                                           '%s' % trans['updatedate'],
                                                           '%s' % trans['standardized']])
                     else:
                             if not result:
                                 dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                                           gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
-                                                          "Sorry! No results found...")
+                                                          _("Sorry! No results found..."))
                                 dialog.run()
                                 dialog.destroy()
                             else:
                         else:
                             dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
-                                                      "Database file is missing!\nPlease provide correct filepath or switch to Online mode")
+                                                      _("Database file is missing!\nPlease provide correct filepath or switch to Online mode"))
                             dialog.run()
                             dialog.destroy()
 
 
         def show_about(self, sender):
                 builder = gtk.Builder()
+                builder.set_translation_domain(APP)
                 builder.add_from_file("%sdata/main-gui.ui" % cur_path)
                 self.about = builder.get_object("aboutdialog1")
                 self.flattr_button = builder.get_object("button3")
 
         def show_prefs(self, sender):
                 builder = gtk.Builder()
+                builder.set_translation_domain(APP)
                 builder.add_from_file("%sdata/main-gui.ui" % cur_path)
                 self.prefs = builder.get_object("prefsdialog")
                 self.entry2 = builder.get_object("entry2")
                     self.prefs.destroy()
 
         def select_database(self, sender):
-            filedialog = gtk.FileChooserDialog("Select Database file:",
+            filedialog = gtk.FileChooserDialog(_("Select Database file:"),
                                               None,
                                               gtk.FILE_CHOOSER_ACTION_OPEN,
                                               (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                               gtk.STOCK_OPEN, gtk.RESPONSE_OK))
             filedialog.set_default_response(gtk.RESPONSE_OK)
             filter = gtk.FileFilter()
-            filter.set_name("DB Files")
+            filter.set_name(_("DB Files"))
             filter.add_mime_type("application/x-sqlite3")
             filter.add_pattern("*.db")
             filedialog.add_filter(filter)
                 if self.searchbox.get_text() == "":
                         dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                                   gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
-                                                  "Nothing to search for...")
+                                                  _("Nothing to search for..."))
                         dialog.run()
                         dialog.destroy()
                 else: