comparison plugins/plugin_xep_0077.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 d46f849664aa
children 783e9d6980ec
comparison
equal deleted inserted replaced
68:9b842086d915 69:86f1f7f6d332
36 "import_name": "XEP_0077", 36 "import_name": "XEP_0077",
37 "type": "XEP", 37 "type": "XEP",
38 "protocols": ["XEP-0077"], 38 "protocols": ["XEP-0077"],
39 "dependencies": [], 39 "dependencies": [],
40 "main": "XEP_0077", 40 "main": "XEP_0077",
41 "description": """Implementation of in-band registration""" 41 "description": _("""Implementation of in-band registration""")
42 } 42 }
43 43
44 class XEP_0077(): 44 class XEP_0077():
45 45
46 def __init__(self, host): 46 def __init__(self, host):
47 info("Plugin XEP_0077 initialization") 47 info(_("Plugin XEP_0077 initialization"))
48 self.host = host 48 self.host = host
49 self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid 49 self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
50 host.bridge.addMethod("in_band_register", ".communication", in_sign='ss', out_sign='s', method=self.in_band_register) 50 host.bridge.addMethod("in_band_register", ".communication", in_sign='ss', out_sign='s', method=self.in_band_register)
51 host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit) 51 host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit)
52 52
57 def reg_ok(self, answer): 57 def reg_ok(self, answer):
58 """Called after the first get IQ""" 58 """Called after the first get IQ"""
59 try: 59 try:
60 x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form) 60 x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form)
61 except IndexError: 61 except IndexError:
62 info("No data form found") 62 info(_("No data form found"))
63 #TODO: manage registration without data form 63 #TODO: manage registration without data form
64 answer_data = {} 64 answer_data = {}
65 answer_data={"reason": "unmanaged", "message":"This gateway can't be managed by SàT, sorry :("} 65 answer_data={"reason": "unmanaged", "message":_("This gateway can't be managed by SàT, sorry :(")}
66 answer_type = "ERROR" 66 answer_type = "ERROR"
67 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 67 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
68 return 68 return
69 69
70 form = data_form.Form.fromElement(x_elem) 70 form = data_form.Form.fromElement(x_elem)
71 xml_data = XMLTools.dataForm2xml(form) 71 xml_data = XMLTools.dataForm2xml(form)
72 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}) 72 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
73 73
74 def reg_err(self, failure): 74 def reg_err(self, failure):
75 """Called when something is wrong with registration""" 75 """Called when something is wrong with registration"""
76 info ("Registration failure: %s" % str(failure.value)) 76 info (_("Registration failure: %s") % str(failure.value))
77 answer_data = {} 77 answer_data = {}
78 answer_data['reason'] = 'unknown' 78 answer_data['reason'] = 'unknown'
79 answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)} 79 answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)}
80 answer_type = "ERROR" 80 answer_type = "ERROR"
81 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 81 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
82 82
83 def unregistrationAnswer(self, answer): 83 def unregistrationAnswer(self, answer):
84 debug ("registration answer: %s" % answer.toXml()) 84 debug (_("registration answer: %s") % answer.toXml())
85 answer_type = "SUCCESS" 85 answer_type = "SUCCESS"
86 answer_data={"message":"Your are now unregistred"} 86 answer_data={"message":_("Your are now unregistred")}
87 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 87 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
88 88
89 def unregistrationFailure(self, failure): 89 def unregistrationFailure(self, failure):
90 info ("Unregistration failure: %s" % str(failure.value)) 90 info (_("Unregistration failure: %s") % str(failure.value))
91 answer_type = "ERROR" 91 answer_type = "ERROR"
92 answer_data = {} 92 answer_data = {}
93 answer_data['reason'] = 'unknown' 93 answer_data['reason'] = 'unknown'
94 answer_data={"message":"Unregistration failed: %s" % failure.value.condition} 94 answer_data={"message":_("Unregistration failed: %s") % failure.value.condition}
95 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 95 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
96 96
97 def registrationAnswer(self, answer): 97 def registrationAnswer(self, answer):
98 debug ("registration answer: %s" % answer.toXml()) 98 debug (_("registration answer: %s") % answer.toXml())
99 answer_type = "SUCCESS" 99 answer_type = "SUCCESS"
100 answer_data={"message":"Registration successfull"} 100 answer_data={"message":_("Registration successfull")}
101 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 101 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
102 if self.triggers.has_key(answer["from"]): 102 if self.triggers.has_key(answer["from"]):
103 self.triggers[answer["from"]](answer["from"]) 103 self.triggers[answer["from"]](answer["from"])
104 del self.triggers[answer["from"]] 104 del self.triggers[answer["from"]]
105 105
106 def registrationFailure(self, failure): 106 def registrationFailure(self, failure):
107 info ("Registration failure: %s" % str(failure.value)) 107 info (_("Registration failure: %s") % str(failure.value))
108 print failure.value.stanza.toXml() 108 print failure.value.stanza.toXml()
109 answer_type = "ERROR" 109 answer_type = "ERROR"
110 answer_data = {} 110 answer_data = {}
111 if failure.value.condition == 'conflict': 111 if failure.value.condition == 'conflict':
112 answer_data['reason'] = 'conflict' 112 answer_data['reason'] = 'conflict'
113 answer_data={"message":"Username already exists, please choose an other one"} 113 answer_data={"message":_("Username already exists, please choose an other one")}
114 else: 114 else:
115 answer_data['reason'] = 'unknown' 115 answer_data['reason'] = 'unknown'
116 answer_data={"message":"Registration failed"} 116 answer_data={"message":_("Registration failed")}
117 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 117 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
118 if self.triggers.has_key(answer["from"]): 118 if self.triggers.has_key(answer["from"]):
119 del self.triggers[answer["from"]] 119 del self.triggers[answer["from"]]
120 120
121 def in_band_submit(self, action, target, fields): 121 def in_band_submit(self, action, target, fields):
129 129
130 def in_band_register(self, target, profile_key='@DEFAULT@'): 130 def in_band_register(self, target, profile_key='@DEFAULT@'):
131 """register to a target JID""" 131 """register to a target JID"""
132 current_jid, xmlstream = self.host.getJidNStream(profile_key) 132 current_jid, xmlstream = self.host.getJidNStream(profile_key)
133 if not xmlstream: 133 if not xmlstream:
134 error ('Asking profile for an non-existant or not connected profile') 134 error (_('Asking for an non-existant or not connected profile'))
135 return "" 135 return ""
136 to_jid = jid.JID(target) 136 to_jid = jid.JID(target)
137 debug("Asking registration for [%s]" % to_jid.full()) 137 debug(_("Asking registration for [%s]") % to_jid.full())
138 reg_request=IQ(xmlstream,'get') 138 reg_request=IQ(xmlstream,'get')
139 reg_request["from"]=current_jid.full() 139 reg_request["from"]=current_jid.full()
140 reg_request["to"] = to_jid.full() 140 reg_request["to"] = to_jid.full()
141 query=reg_request.addElement('query', NS_REG) 141 query=reg_request.addElement('query', NS_REG)
142 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err) 142 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err)