diff plugins/plugin_xep_0054.py @ 69:86f1f7f6d332

i18n first draft - gettext support added in SàT - first draft of french translation - added README with a HOWTO for translators
author Goffi <goffi@goffi.org>
date Wed, 03 Mar 2010 17:12:23 +1100
parents 8147b4f40809
children f271fff3a713
line wrap: on
line diff
--- a/plugins/plugin_xep_0054.py	Thu Feb 25 17:09:18 2010 +1100
+++ b/plugins/plugin_xep_0054.py	Wed Mar 03 17:12:23 2010 +1100
@@ -59,13 +59,13 @@
 "dependencies": [],
 "main": "XEP_0054",
 "handler": "yes",
-"description": """Implementation of vcard-temp"""
+"description": _("""Implementation of vcard-temp""")
 }
 
 class XEP_0054():
 
     def __init__(self, host):
-        info("Plugin XEP_0054 initialization")
+        info(_("Plugin XEP_0054 initialization"))
         self.host = host
         self.avatar_path = os.path.expanduser(self.host.get_const('local_dir') + AVATAR_PATH)
         self.vcard_cache = host.memory.getPrivate("vcard_cache") or {}  #used to store nicknames and avatar, key = jid
@@ -108,24 +108,24 @@
         """Parse a <PHOTO> elem and save the picture"""
         for elem in photo_xml.elements():
             if elem.name == 'TYPE':
-                info('Photo of type [%s] found' % str(elem))
+                info(_('Photo of type [%s] found') % str(elem))
             if elem.name == 'BINVAL':
-                debug('Decoding binary')
+                debug(_('Decoding binary'))
                 decoded = b64decode(str(elem))
                 hash = sha1(decoded).hexdigest()
                 filename = self.avatar_path+'/'+hash
                 if not os.path.exists(filename):
                     with open(filename,'wb') as file:
                         file.write(decoded)
-                    debug("file saved to %s" % hash)
+                    debug(_("file saved to %s") % hash)
                 else:
-                    debug("file [%s] already in cache" % hash)
+                    debug(_("file [%s] already in cache") % hash)
                 return hash
 
     @defer.deferredGenerator
     def vCard2Dict(self, vcard, target):
         """Convert a VCard to a dict, and save binaries"""
-        debug ("parsing vcard")
+        debug (_("parsing vcard"))
         dictionary = {}
         d = defer.Deferred()
         
@@ -151,24 +151,24 @@
                 else:
                     self.update_cache(target, 'avatar', dictionary['avatar'])
             else:
-                info ('FIXME: [%s] VCard tag is not managed yet' % elem.name)
+                info (_('FIXME: [%s] VCard tag is not managed yet') % elem.name)
 
         yield dictionary
 
     def vcard_ok(self, answer):
         """Called after the first get IQ"""
-        debug ("VCard found")
+        debug (_("VCard found"))
 
         if answer.firstChildElement().name == "vCard":
             d = self.vCard2Dict(answer.firstChildElement(), jid.JID(answer["from"]))
             d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data))
         else:
-            error ("FIXME: vCard not found as first child element")
+            error (_("FIXME: vCard not found as first child element"))
             self.host.bridge.actionResult("SUPPRESS", answer['id'], {}) #FIXME: maybe an error message would be best
 
     def vcard_err(self, failure):
         """Called when something is wrong with registration"""
-        error ("Can't find VCard of %s" % failure.value.stanza['from'])
+        error (_("Can't find VCard of %s") % failure.value.stanza['from'])
         self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}) #FIXME: maybe an error message would be best
   
     def getCard(self, target, profile_key='@DEFAULT@'):
@@ -177,10 +177,10 @@
         @result: id to retrieve the profile"""
         current_jid, xmlstream = self.host.getJidNStream(profile_key)
         if not xmlstream:
-            error ('Asking profile for an non-existant or not connected profile')
+            error (_('Asking vcard for an non-existant or not connected profile'))
             return ""
         to_jid = jid.JID(target)
-        debug("Asking for %s's VCard" % to_jid.userhost())
+        debug(_("Asking for %s's VCard") % to_jid.userhost())
         reg_request=IQ(xmlstream,'get')
         reg_request["from"]=current_jid.full()
         reg_request["to"] = to_jid.userhost()
@@ -195,7 +195,7 @@
         """
         filename = self.avatar_path+'/'+hash
         if not os.path.exists(filename):
-            error ("Asking for an uncached avatar [%s]" %  hash)
+            error (_("Asking for an uncached avatar [%s]") %  hash)
             return ""
         return filename
 
@@ -242,5 +242,5 @@
                 hash = str(elem)
                 old_avatar = self.plugin_parent.get_cache(to_jid, 'avatar')
                 if not old_avatar or old_avatar != hash:
-                    debug('New avatar found, requesting vcard')
+                    debug(_('New avatar found, requesting vcard'))
                     self.plugin_parent.getCard(to_jid.userhost(), self.parent.profile)