[Git][gajim/python-nbxmpp][master] Dont try to guess system language

Philipp Hörist gitlab at dev.gajim.org
Mon Jan 7 23:24:15 CET 2019


Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
1db41e01 by Philipp Hörist at 2019-01-07T22:23:22Z
Dont try to guess system language

getdefaultlocale() is not a good way for determining the users configured language

Let the client figure it out and pass it to nbxmpp

- - - - -


3 changed files:

- nbxmpp/bosh.py
- nbxmpp/client_nb.py
- nbxmpp/dispatcher_nb.py


Changes:

=====================================
nbxmpp/bosh.py
=====================================
@@ -45,10 +45,7 @@ class NonBlockingBOSH(NonBlockingTransport):
             idlequeue, estabilish_tls, certs, tls_version, cipher_list)
 
         self.bosh_sid = None
-        if locale.getdefaultlocale()[0]:
-            self.bosh_xml_lang = locale.getdefaultlocale()[0].split('_')[0]
-        else:
-            self.bosh_xml_lang = 'en'
+        self.bosh_xml_lang = self._owner.lang
 
         self.http_version = 'HTTP/1.1'
         self.http_persistent = True


=====================================
nbxmpp/client_nb.py
=====================================
@@ -42,7 +42,7 @@ class NonBlockingClient:
     handling, whereas underlying modules take care of feature-specific logic
     """
 
-    def __init__(self, domain, idlequeue, caller=None):
+    def __init__(self, domain, idlequeue, caller=None, lang='en'):
         """
         Caches connection data
 
@@ -50,9 +50,11 @@ class NonBlockingClient:
         :param idlequeue: processing idlequeue
         :param caller: calling object - it has to implement methods
             _event_dispatcher which is called from dispatcher instance
+        :param lang: the preferred stream language
         """
         self.Namespace = protocol.NS_CLIENT
         self.defaultNamespace = self.Namespace
+        self.lang = lang
 
         self.idlequeue = idlequeue
         self.disconnect_handlers = []


=====================================
nbxmpp/dispatcher_nb.py
=====================================
@@ -239,9 +239,7 @@ class XMPPDispatcher(PlugIn):
         self._metastream.setAttr('version', '1.0')
         self._metastream.setAttr('xmlns:stream', NS_STREAMS)
         self._metastream.setAttr('to', self._owner.Server)
-        if locale.getdefaultlocale()[0]:
-            self._metastream.setAttr('xml:lang',
-                    locale.getdefaultlocale()[0].split('_')[0])
+        self._metastream.setAttr('xml:lang', self._owner.lang)
         self._owner.send("%s%s>" % (XML_DECLARATION, str(self._metastream)[:-2]))
 
     def _check_stream_start(self, ns, tag, attrs):
@@ -703,9 +701,7 @@ class BOSHDispatcher(XMPPDispatcher):
         self._metastream.setAttr('version', '1.0')
         self._metastream.setAttr('xmlns:stream', NS_STREAMS)
         self._metastream.setAttr('to', self._owner.Server)
-        if locale.getdefaultlocale()[0]:
-            self._metastream.setAttr('xml:lang',
-                    locale.getdefaultlocale()[0].split('_')[0])
+        self._metastream.setAttr('xml:lang', self._owner.lang)
 
         self.restart = True
         self._owner.Connection.send_init(after_SASL=self.after_SASL)



View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/1db41e016b94b22d89397a14f0bad8800aa40b1c

-- 
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/1db41e016b94b22d89397a14f0bad8800aa40b1c
You're receiving this email because of your account on dev.gajim.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gajim.org/pipermail/commits/attachments/20190107/40ed2f83/attachment-0001.html>


More information about the Commits mailing list