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,
|
secure_tuple = (self._current_type, cacerts, mycerts, tls_version,
|
||||||
cipher_list, self._current_host['alpn'])
|
cipher_list, self._current_host['alpn'])
|
||||||
|
|
||||||
|
lang = i18n.get_rfc5646_lang()
|
||||||
|
log.info('Set stream language: %s', lang)
|
||||||
|
|
||||||
con = nbxmpp.NonBlockingClient(
|
con = nbxmpp.NonBlockingClient(
|
||||||
domain=self._hostname,
|
domain=self._hostname,
|
||||||
caller=self,
|
caller=self,
|
||||||
idlequeue=app.idlequeue,
|
idlequeue=app.idlequeue,
|
||||||
lang=i18n.LANG)
|
lang=lang)
|
||||||
|
|
||||||
if self._sm_resume_data:
|
if self._sm_resume_data:
|
||||||
con.set_resume_data(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():
|
if locale_dir.is_dir():
|
||||||
yield str(locale_dir)
|
yield str(locale_dir)
|
||||||
|
|
||||||
|
|
||||||
def get_default_lang():
|
def get_default_lang():
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
import ctypes
|
import ctypes
|
||||||
windll = ctypes.windll.kernel32
|
windll = ctypes.windll.kernel32
|
||||||
lang = locale.windows_locale[windll.GetUserDefaultUILanguage()]
|
return locale.windows_locale[windll.GetUserDefaultUILanguage()]
|
||||||
return lang[:2]
|
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
from AppKit import NSLocale
|
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()
|
return NSLocale.currentLocale().languageCode()
|
||||||
|
|
||||||
default = locale.getdefaultlocale()[0]
|
return locale.getdefaultlocale()[0] or 'en'
|
||||||
if default is not None:
|
|
||||||
return default[:2]
|
|
||||||
return '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():
|
def initialize_direction_mark():
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
|
@ -553,7 +553,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
% phrase_for_url
|
% phrase_for_url
|
||||||
else:
|
else:
|
||||||
link = 'http://%s.wikipedia.org/wiki/Special:Search?search=%s'\
|
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'))
|
item = Gtk.MenuItem.new_with_mnemonic(_('Read _Wikipedia Article'))
|
||||||
id_ = item.connect('activate', self.visit_url_from_menuitem, link)
|
id_ = item.connect('activate', self.visit_url_from_menuitem, link)
|
||||||
self.handlers[id_] = item
|
self.handlers[id_] = item
|
||||||
|
@ -569,7 +569,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
% phrase_for_url
|
% phrase_for_url
|
||||||
else:
|
else:
|
||||||
link = 'http://%s.wiktionary.org/wiki/Special:Search?search=%s'\
|
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)
|
id_ = item.connect('activate', self.visit_url_from_menuitem, link)
|
||||||
self.handlers[id_] = item
|
self.handlers[id_] = item
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue