Added translation mechanism (supplied by Nicolas Graziano). MB#5834
authorAndrew Flegg <andrew@serenity.(none)>
Sat, 12 Dec 2009 19:50:27 +0000 (19:50 +0000)
committerAndrew Flegg <andrew@serenity.(none)>
Sat, 12 Dec 2009 19:50:27 +0000 (19:50 +0000)
package/Makefile
package/po/Makefile [new file with mode: 0644]
package/src/gui.py

index dfd99ba..7a26939 100644 (file)
@@ -6,6 +6,7 @@ compile:
        perl -ni -e 'print; exit if /^XB-Maemo-Icon-26:$$/' debian/control
        uuencode -m share/hermes-48.png - | perl -ne 'print " $$_" unless $$. == 1 or /^====$$/' >>debian/control
        py_compilefiles src/*.py
+       cd po && $(MAKE) compile
        mkdir bin
 
 install:
@@ -18,12 +19,14 @@ install:
        install -D -m 0644 -o root -g root share/hermes.desktop ${DESTDIR}/usr/share/applications/hildon/hermes.desktop
        install -D -m 0644 -o root -g root share/hermes.service ${DESTDIR}/usr/share/dbus-1/services/hermes.service
        chmod 755 ${DESTDIR}/opt/hermes/lib/gui.py
+       cd po && $(MAKE) install 
 
 clean:
        rm -f src/*.py[oc]
        rm -f build-stamp configure-stamp
        rm -rf debian/hermes bin
        find . -name *~ -exec rm -f {} \;
+       cd po && $(MAKE) clean
 
 package:
        dpkg-buildpackage -rfakeroot -uc -us
diff --git a/package/po/Makefile b/package/po/Makefile
new file mode 100644 (file)
index 0000000..7ca8641
--- /dev/null
@@ -0,0 +1,77 @@
+
+
+GETTEXT_PACKAGE = hermes
+PACKAGE = hermes
+
+SHELL = /bin/sh
+
+prefix = /opt/$(PACKAGE)
+DATADIRNAME = share
+itlocaledir = $(prefix)/$(DATADIRNAME)/locale
+
+INSTALL = /scratchbox/tools/bin/install -c
+INSTALL_DATA = ${INSTALL} -m 644
+
+GMSGFMT = /scratchbox/tools/bin/msgfmt
+MSGFMT = /scratchbox/tools/bin/msgfmt
+XGETTEXT = /scratchbox/tools/bin/xgettext
+MSGMERGE = /scratchbox/tools/bin/msgmerge 
+
+PO_LINGUAS= 
+
+USE_LINGUAS= 
+
+POFILES=$(shell LINGUAS="$(PO_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.po "; done)
+
+DISTFILES = Makefile POTFILES.in $(POFILES)
+EXTRA_DISTFILES = ChangeLog POTFILES.skip Makevars LINGUAS
+
+POTFILES = \
+       ../src/gui.py \
+# This comment gets stripped out
+
+CATALOGS=$(shell LINGUAS="$(USE_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.gmo "; done)
+
+.SUFFIXES:
+.SUFFIXES: .po .gmo .mo 
+
+.po.mo:
+       $(MSGFMT) -o $@ $<
+
+.po.gmo:
+       file=`echo $* | sed 's,.*/,,'`.gmo \
+         && rm -f $$file && $(GMSGFMT) -o $$file $<
+
+all: compile
+
+compile: $(CATALOGS)
+
+$(GETTEXT_PACKAGE).pot: $(POTFILES)
+       $(XGETTEXT) --package-name=$(PACKAGE) -o $(GETTEXT_PACKAGE).pot $(POTFILES) 
+
+install: all
+       linguas="$(USE_LINGUAS)"; \
+       for lang in $$linguas; do \
+         dir=$(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES; \
+         mkdir -p $$dir; \
+         if test -r $$lang.gmo; then \
+           $(INSTALL_DATA) $$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \
+           echo "installing $$lang.gmo as $$dir/$(GETTEXT_PACKAGE).mo"; \
+         fi; \
+       done
+
+clean:         
+       rm -f *.mo *.gmo
+
+update-po: 
+       $(MAKE) $(GETTEXT_PACKAGE).pot
+       linguas="$(USE_LINGUAS)"; \
+       for lang in $$linguas; do \
+         echo "$$lang:"; \
+         if test -r $$lang.po; then \
+           $(MSGMERGE) -U $$lang.po $(GETTEXT_PACKAGE).pot; \
+         else \
+           cp $(GETTEXT_PACKAGE).pot $$lang.po; \
+         fi; \
+       done
+
index 257e8e1..1d96731 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+import gettext
 import gtk, gobject
 import traceback
 import time
@@ -22,14 +23,15 @@ class HermesGUI(WimpWorks):
 
   # -----------------------------------------------------------------------
   def __init__(self):
+    gettext.install('hermes','/opt/hermes/share/locale/')
     WimpWorks.__init__(self, 'Hermes', version = '0.2.0', dbus_name = 'org.maemo.hermes')
     self.set_background('background.png')
     
     layout = wimpworks.HildonMainScreenLayout(offset = 0.8, container = self)
-    layout.add_button('Retrieve', "Get contacts' missing info")
-    layout.add_button('Refresh', "Update contacts' info")
+    layout.add_button(_('Retrieve'), _("Get contacts' missing info"))
+    layout.add_button(_('Refresh'), _("Update contacts' info"))
 
-    self.add_menu_action("Accounts")
+    self.add_menu_action(_("Accounts"))
     self.menu.show_all()
 
   
@@ -45,8 +47,8 @@ class HermesGUI(WimpWorks):
 
   # -----------------------------------------------------------------------
   def do_accounts(self, widget = None):
-    dialog = gtk.Dialog('Accounts', self.main_window)
-    dialog.add_button('Save', gtk.RESPONSE_OK)
+    dialog = gtk.Dialog(_('Accounts'), self.main_window)
+    dialog.add_button(_('Save'), gtk.RESPONSE_OK)
 
     #pa = hildon.PannableArea()
     #dialog.vbox.add(pa)
@@ -55,23 +57,23 @@ class HermesGUI(WimpWorks):
     #pa.add(content)
     #pa.set_size_request(600, 380)
 
-    use_facebook = self.new_checkbox('Use Facebook', content)
+    use_facebook = self.new_checkbox(_('Use Facebook'), content)
     use_facebook.set_active(self.get_use_facebook())
 
     indent = self.new_indent(content)
-    self.link_control(use_facebook, gtk.Label('Note: authentication via web page'), indent)
+    self.link_control(use_facebook, gtk.Label(_('Note: authentication via web page')), indent)
     
-    fb_empty = self.link_control(use_facebook, self.new_checkbox('Create birthday-only contacts'), indent)
+    fb_empty = self.link_control(use_facebook, self.new_checkbox(_('Create birthday-only contacts')), indent)
     fb_empty.set_active(self.get_create_empty())
 
-    use_twitter = self.new_checkbox('Use Twitter', content)
+    use_twitter = self.new_checkbox(_('Use Twitter'), content)
     use_twitter.set_active(self.get_use_twitter())
 
     indent = self.new_indent(content)
-    tw_user = self.link_control(use_twitter, self.new_input('Twitter username'), indent)
+    tw_user = self.link_control(use_twitter, self.new_input(_('Twitter username')), indent)
     tw_user.set_text(self.get_twitter_credentials()[0])
 
-    tw_pass = self.link_control(use_twitter, self.new_input('Twitter password', password = True), indent)
+    tw_pass = self.link_control(use_twitter, self.new_input(_('Twitter password'), password = True), indent)
     tw_pass.set_text(self.get_twitter_credentials()[1])
 
     dialog.show_all()
@@ -108,40 +110,40 @@ class HermesGUI(WimpWorks):
       except urllib2.HTTPError, e:
         traceback.print_exc()
         if e.code == 401:
-          gobject.idle_add(self.report_error, 'Authentication problem. Check credentials.', True)
+          gobject.idle_add(self.report_error, _('Authentication problem. Check credentials.'), True)
         else:
-          gobject.idle_add(self.report_error, 'Network connection error. Check connectivity.')
+          gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
 
       except urllib2.URLError, e:
         traceback.print_exc()
-        gobject.idle_add(self.report_error, 'Network connection error. Check connectivity.')
+        gobject.idle_add(self.report_error, _('Network connection error. Check connectivity.'))
       
       except Exception, e:
         traceback.print_exc()
-        gobject.idle_add(self.report_error, 'Something went wrong: ' + e.message)
+        gobject.idle_add(self.report_error, _('Something went wrong: ') + e.message)
 
 
   # -----------------------------------------------------------------------
   def open_summary(self, fb2c):
     gobject.idle_add(self.main_window.set_property, 'sensitive', True)
 
-    dialog = gtk.Dialog('Summary', self.main_window)
-    dialog.add_button('Done', gtk.RESPONSE_OK)
+    dialog = gtk.Dialog(_('Summary'), self.main_window)
+    dialog.add_button(_('Done'), gtk.RESPONSE_OK)
     
     button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
-                           title = 'Updated %d contacts' % (len(fb2c.updated)))
+                           title = _('Updated %d contacts') % (len(fb2c.updated)))
     button.connect('clicked', self.show_contacts, fb2c, fb2c.updated)
     button.set_property('sensitive', len(fb2c.updated) > 0)
     dialog.vbox.add(button)
     
     button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
-                           title = 'Matched %d contacts' % (len(fb2c.matched)))
+                           title = _('Matched %d contacts') % (len(fb2c.matched)))
     button.connect('clicked', self.show_contacts, fb2c, fb2c.matched)
     button.set_property('sensitive', len(fb2c.matched) > 0)
     dialog.vbox.add(button)
     
     button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
-                           title = '%d contacts unmatched' % (len(fb2c.unmatched)))
+                           title = _('%d contacts unmatched') % (len(fb2c.unmatched)))
     button.connect('clicked', self.show_contacts, fb2c, fb2c.unmatched)
     button.set_property('sensitive', len(fb2c.unmatched) > 0)
     dialog.vbox.add(button)
@@ -155,7 +157,7 @@ class HermesGUI(WimpWorks):
   def show_contacts(self, widget, fb2c, contacts):
     view = contactview.ContactView(contacts)
 
-    dialog = gtk.Dialog('Contacts', self.main_window)
+    dialog = gtk.Dialog(_('Contacts'), self.main_window)
     view.connect('contact-activated', self.map_contact, fb2c)
     dialog.vbox.add(view)
     dialog.show_all()
@@ -169,7 +171,7 @@ class HermesGUI(WimpWorks):
     view = mapcontact.MapContact(fb2c.friends, contact)
 
     dialog = gtk.Dialog(contact.get_name(), self.main_window)
-    dialog.add_button('Update', gtk.RESPONSE_OK)
+    dialog.add_button(_('Update'), gtk.RESPONSE_OK)
     dialog.vbox.add(view)
     dialog.show_all()
     
@@ -179,9 +181,9 @@ class HermesGUI(WimpWorks):
       friend = view.get_selected_friend()
       if friend:
         if 'contact' in friend and friend['contact'] == contact:
-          hildon.hildon_banner_show_information(self.main_window, '', "Removing existing mappings is not yet supported")
+          hildon.hildon_banner_show_information(self.main_window, '', _("Removing existing mappings is not yet supported"))
         elif view.contact_mapped:
-          hildon.hildon_banner_show_information(self.main_window, '', "Changing existing mappings is not yet supported")
+          hildon.hildon_banner_show_information(self.main_window, '', _("Changing existing mappings is not yet supported"))
         else:
           if fb2c.update_contact(contact, friend, False):
             fb2c.addresses.commit_contact(contact)
@@ -190,7 +192,7 @@ class HermesGUI(WimpWorks):
   # -----------------------------------------------------------------------
   def need_auth(self, main = False):
     if main:
-      hildon.hildon_banner_show_information(self.main_window, '', "Need to authenticate with Facebook")
+      hildon.hildon_banner_show_information(self.main_window, '', _("Need to authenticate with Facebook"))
     else:
       gobject.idle_add(self.need_auth, True)
     
@@ -198,9 +200,9 @@ class HermesGUI(WimpWorks):
   # -----------------------------------------------------------------------
   def block_for_auth(self, main = False, lock = None):
     if main:
-      note = gtk.Dialog('Facebook authorisation', self.main_window)
-      note.add_button("Validate", gtk.RESPONSE_OK)
-      note.vbox.add(gtk.Label("\nPress 'Validate' once Facebook has\nbeen authenticated in web browser.\n"))
+      note = gtk.Dialog(_('Facebook authorisation'), self.main_window)
+      note.add_button(_("Validate"), gtk.RESPONSE_OK)
+      note.vbox.add(gtk.Label(_("\nPress 'Validate' once Facebook has\nbeen authenticated in web browser.\n")))
 
       note.show_all()
       result = note.run()
@@ -221,7 +223,7 @@ class HermesGUI(WimpWorks):
     if main:
       if i == 0:
         self.progressbar = gtk.ProgressBar()
-        self.progressnote = gtk.Dialog("Fetching friends' info", self.main_window)
+        self.progressnote = gtk.Dialog(_("Fetching friends' info"), self.main_window)
         self.progressnote.vbox.add(self.progressbar)
         hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 1)
         
@@ -229,7 +231,7 @@ class HermesGUI(WimpWorks):
         
       elif i < j:
         if i == 1:
-          self.progressnote.set_title("Updating contacts")
+          self.progressnote.set_title(_("Updating contacts"))
           hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 0)
           
         self.progressbar.set_fraction(float(i) / float(j))