i18n first draft

- gettext support added in SàT
- first draft of french translation
- added README with a HOWTO for translators
This commit is contained in:
Goffi 2010-03-03 17:12:23 +11:00
commit 4a293cdaa1

View file

@ -59,13 +59,13 @@ PLUGIN_INFO = {
"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 @@ class XEP_0054():
"""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 @@ class XEP_0054():
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 @@ class XEP_0054():
@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 @@ class XEP_0054():
"""
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 @@ class XEP_0054_handler(XMPPHandler):
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)