diff frontends/jp/jp @ 70:8f2ed279784b

i18n - gettext support added in frontends - first draft of frontends french translation
author Goffi <goffi@goffi.org>
date Fri, 05 Mar 2010 20:33:10 +1100
parents a5b5fb5fc9fd
children cb904fa7de3c
line wrap: on
line diff
--- a/frontends/jp/jp	Wed Mar 03 17:12:23 2010 +1100
+++ b/frontends/jp/jp	Fri Mar 05 20:33:10 2010 +1100
@@ -45,6 +45,9 @@
                     format='%(message)s')
 ###
 
+import gettext
+gettext.install('jp', "i18n", unicode=True)
+
 import sys
 import os
 from os.path import abspath, basename, dirname
@@ -57,8 +60,8 @@
 try:
     from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
 except ImportError, e:
-        info ('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')
-        info ('Progress bar deactivated\n--\n')
+        info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
+        info (_('Progress bar deactivated\n--\n'))
         pbar_available=False
 
 
@@ -71,33 +74,33 @@
 
     def check_options(self):
         """Check command line options"""
-        usage="""
+        usage=_("""
         %prog [options] [FILE1 FILE2 ...] JID
         %prog -w [options] [JID1 JID2 ...]
 
         %prog --help for options list
-        """
+        """)
         parser = OptionParser(usage=usage,version=about)
 
         parser.add_option("-b", "--bz2", action="store_true", default=False,
-                    help="Make a bzip2 tarball")
+                    help=_("Make a bzip2 tarball"))
         parser.add_option("-w", "--wait-file", action="store_true", default=False,
-                    help="Wait for a file to be sent by a contact")
+                    help=_("Wait for a file to be sent by a contact"))
         parser.add_option("-m", "--multiple", action="store_true", default=False,
-                    help="Accept multiple files (you'll have to stop manually)")
+                    help=_("Accept multiple files (you'll have to stop manually)"))
         parser.add_option("-f", "--force", action="store_true", default=False,
-                    help="Force overwritting of existing files")
+                    help=_("Force overwritting of existing files"))
         parser.add_option("-p", "--progress", action="store_true", default=False,
-                    help="Show progress bar")
+                    help=_("Show progress bar"))
         parser.add_option("-s", "--separate", action="store_true", default=False,
-                    help="Separate xmpp messages: send one message per line instead of one message alone.")
+                    help=_("Separate xmpp messages: send one message per line instead of one message alone."))
         parser.add_option("-n", "--new-line", action="store_true", default=False,
-                    help="Add a new line at the beginning of the input (usefull for ascii art ;))")
+                    help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
 
         (self.options, args) = parser.parse_args()
 
         if len(args) < 1 and not self.options.wait_file:
-            parser.error("You must specify the destination JID (Jabber ID)")
+            parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8'))
 
         if self.options.wait_file:
             #several jid
@@ -106,13 +109,13 @@
             #one dest_jid, other args are files
             self.dest_jid = JID(args[-1])
             if not self.dest_jid.is_valid:
-                error ("%s is not a valid JID !", self.dest_jid)
+                error (_("%s is not a valid JID !"), self.dest_jid)
                 exit(1)
             self.files = args[:-1]
 
         if not pbar_available and self.options.progress:
             self.options.progress = False
-            error ("Option progress is not available, deactivated.")
+            error (_("Option progress is not available, deactivated."))
 
         if self.options.progress or self.options.wait_file:
             self.start_loop = True  #We have to use loop for these options
@@ -125,7 +128,7 @@
     def check_jabber_status(self):
         """Check that jabber status is allright"""
         if not self.bridge.isConnected():
-            error("SAT is not conneted, please connect before using jp")
+            error(_("SAT is not conneted, please connect before using jp"))
             exit(1)
 
 
@@ -149,27 +152,27 @@
 
         for file in self.files:
             if not os.path.exists(file):
-                error ("File [%s] doesn't exist !" % file)
+                error (_("File [%s] doesn't exist !") % file)
                 exit(1)
             if not self.options.bz2 and os.path.isdir(file):
-                error ("[%s] is a dir ! Please send files inside or use compression" % file)
+                error (_("[%s] is a dir ! Please send files inside or use compression") % file)
                 exit(1)
 
         if self.options.bz2:
             tmpfile = (basename(self.files[0]) or basename(dirname(self.files[0])) ) + '.tar.bz2' #FIXME: tmp, need an algorithm to find a good name/path
             if os.path.exists(tmpfile):
-                error ("tmp file (%s) already exists ! Please remove it", tmpfile)
+                error (_("tmp file (%s) already exists ! Please remove it"), tmpfile)
                 exit(1)
-            warning("bz2 is an experimental option at an early dev stage, use with caution")
+            warning(_("bz2 is an experimental option at an early dev stage, use with caution"))
             #FIXME: check free space, writting perm, tmp dir, filename (watch for OS used)
-            info("Starting compression, please wait...")
+            info(_("Starting compression, please wait..."))
             sys.stdout.flush()
             bz2=tarfile.open(tmpfile, "w:bz2")
             for file in self.files:
-                info("Adding %s", file)
+                info(_("Adding %s"), file)
                 bz2.add(file)
             bz2.close()
-            info("OK !")
+            info(_("OK !"))
             path = abspath(tmpfile)
             self.transfert_id = self.bridge.sendFile(self.dest_jid, path)
         else:
@@ -190,11 +193,11 @@
 
             if self.options.force or not os.path.exists(answer_data["dest_path"]):
                 self.bridge.confirmationAnswer(id, True, answer_data)
-                info("Accepted file [%s] from %s", data['filename'], data['from'])
+                info(_("Accepted file [%(filename)s] from %(sender)s") % {'filename':data['filename'], 'sender':data['from']})
                 self.transfert_id = id
             else:
                 self.bridge.confirmationAnswer(id, False, answer_data)
-                warning("Refused file [%s] from %s: a file with the same name already exist", data['filename'], data['from'])
+                warning(_("Refused file [%(filename)s] from %(sender)s: a file with the same name already exist") % {'filename':data['filename'], 'sender':data['from']})
                 
 
             if not self.options.multiple and not self.options.progress:
@@ -203,7 +206,7 @@
                 
     def actionResult(self, type, id, data):
         #FIXME
-        info ("FIXME: actionResult not implemented")
+        info (_("FIXME: actionResult not implemented"))
 
     def wait_file(self):
         """Wait for a file and write it on local dir"""
@@ -217,7 +220,7 @@
                     data['position'] = '0'
                 if not self.pbar:
                     #first answer, we must construct the bar
-                    self.pbar = ProgressBar(int(data['size']),["Progress: ",Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()])
+                    self.pbar = ProgressBar(int(data['size']),[_("Progress: "),Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()])
                     self.pbar.start()
                     
                 self.pbar.update(int(data['position']))
@@ -248,7 +251,7 @@
             try:
                 self.loop.run()
             except KeyboardInterrupt:
-                info("User interruption: good bye")
+                info(_("User interruption: good bye"))
 
 
 if __name__ == "__main__":