[Git][gajim/gajim][master] Detect full language code

Philipp Hörist gitlab at dev.gajim.org
Sat Jan 19 20:40:17 CET 2019


Philipp Hörist pushed to branch master at gajim / gajim


Commits:
cf8eafff by Philipp Hörist at 2019-01-19T19:40:06Z
Detect full language code

Previously we only used short language codes (en, de, fr)

- Add conversion method to rfc5646 format

- - - - -


3 changed files:

- gajim/common/connection.py
- gajim/common/i18n.py
- gajim/conversation_textview.py


Changes:

=====================================
gajim/common/connection.py
=====================================
@@ -1059,11 +1059,14 @@ class Connection(CommonConnection, ConnectionHandlers):
         secure_tuple = (self._current_type, cacerts, mycerts, tls_version,
                         cipher_list, self._current_host['alpn'])
 
+        lang = i18n.get_rfc5646_lang()
+        log.info('Set stream language: %s', lang)
+
         con = nbxmpp.NonBlockingClient(
             domain=self._hostname,
             caller=self,
             idlequeue=app.idlequeue,
-            lang=i18n.LANG)
+            lang=lang)
 
         if self._sm_resume_data:
             con.set_resume_data(self._sm_resume_data)


=====================================
gajim/common/i18n.py
=====================================
@@ -69,21 +69,33 @@ def iter_locale_dirs():
         if locale_dir.is_dir():
             yield str(locale_dir)
 
+
 def get_default_lang():
     if os.name == "nt":
         import ctypes
         windll = ctypes.windll.kernel32
-        lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
-        return lang[:2]
+        return locale.windows_locale[windll.GetUserDefaultUILanguage()]
 
     if sys.platform == "darwin":
         from AppKit import NSLocale
+        # FIXME: This returns a two letter language code (en, de, fr)
+        # We need a way to get en_US, de_DE etc.
         return NSLocale.currentLocale().languageCode()
 
-    default = locale.getdefaultlocale()[0]
-    if default is not None:
-        return default[:2]
-    return 'en'
+    return locale.getdefaultlocale()[0] or 'en'
+
+
+def get_rfc5646_lang(lang=None):
+    if lang is None:
+        lang = LANG
+    return lang.replace('_', '-')
+
+
+def get_short_lang_code(lang=None):
+    if lang is None:
+        lang = LANG
+    return lang[:2]
+
 
 def initialize_direction_mark():
     from gi.repository import Gtk


=====================================
gajim/conversation_textview.py
=====================================
@@ -553,7 +553,7 @@ class ConversationTextview(GObject.GObject):
                         % phrase_for_url
             else:
                 link = 'http://%s.wikipedia.org/wiki/Special:Search?search=%s'\
-                        % (i18n.LANG, phrase_for_url)
+                        % (i18n.get_short_lang_code(), phrase_for_url)
             item = Gtk.MenuItem.new_with_mnemonic(_('Read _Wikipedia Article'))
             id_ = item.connect('activate', self.visit_url_from_menuitem, link)
             self.handlers[id_] = item
@@ -569,7 +569,7 @@ class ConversationTextview(GObject.GObject):
                             % phrase_for_url
                 else:
                     link = 'http://%s.wiktionary.org/wiki/Special:Search?search=%s'\
-                            % (i18n.LANG, phrase_for_url)
+                            % (i18n.get_short_lang_code(), phrase_for_url)
                 id_ = item.connect('activate', self.visit_url_from_menuitem, link)
                 self.handlers[id_] = item
             else:



View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/cf8eafffb28fa4acb48e4eda44be35b7db475d77

-- 
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/cf8eafffb28fa4acb48e4eda44be35b7db475d77
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/20190119/995f599c/attachment-0001.html>


More information about the Commits mailing list