Detect full language code
Previously we only used short language codes (en, de, fr) - Add conversion method to rfc5646 format
This commit is contained in:
parent
a9994b791b
commit
cf8eafffb2
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue