Fix locale init
- date/time wasn't localised correctly on startup
This commit is contained in:
parent
dd777d6e43
commit
025950c05e
|
@ -48,7 +48,7 @@ from about import *
|
||||||
from help import *
|
from help import *
|
||||||
from iconglossary import *
|
from iconglossary import *
|
||||||
from connect import *
|
from connect import *
|
||||||
import locale as pythonlocale
|
import locale
|
||||||
import sys
|
import sys
|
||||||
from time import strftime, localtime, gmtime
|
from time import strftime, localtime, gmtime
|
||||||
import time
|
import time
|
||||||
|
@ -83,7 +83,7 @@ def _translate(context, text, disambiguation = None, encoding = None, number = N
|
||||||
else:
|
else:
|
||||||
return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, number)
|
return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, number)
|
||||||
|
|
||||||
def change_translation(locale):
|
def change_translation(newlocale):
|
||||||
global qmytranslator, qsystranslator
|
global qmytranslator, qsystranslator
|
||||||
try:
|
try:
|
||||||
if not qmytranslator.isEmpty():
|
if not qmytranslator.isEmpty():
|
||||||
|
@ -97,29 +97,29 @@ def change_translation(locale):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
qmytranslator = QtCore.QTranslator()
|
qmytranslator = QtCore.QTranslator()
|
||||||
translationpath = os.path.join (shared.codePath(), 'translations', 'bitmessage_' + locale)
|
translationpath = os.path.join (shared.codePath(), 'translations', 'bitmessage_' + newlocale)
|
||||||
qmytranslator.load(translationpath)
|
qmytranslator.load(translationpath)
|
||||||
QtGui.QApplication.installTranslator(qmytranslator)
|
QtGui.QApplication.installTranslator(qmytranslator)
|
||||||
|
|
||||||
qsystranslator = QtCore.QTranslator()
|
qsystranslator = QtCore.QTranslator()
|
||||||
if shared.frozen:
|
if shared.frozen:
|
||||||
translationpath = os.path.join (shared.codePath(), 'translations', 'qt_' + locale)
|
translationpath = os.path.join (shared.codePath(), 'translations', 'qt_' + newlocale)
|
||||||
else:
|
else:
|
||||||
translationpath = os.path.join (str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + locale)
|
translationpath = os.path.join (str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
|
||||||
qsystranslator.load(translationpath)
|
qsystranslator.load(translationpath)
|
||||||
QtGui.QApplication.installTranslator(qsystranslator)
|
QtGui.QApplication.installTranslator(qsystranslator)
|
||||||
|
|
||||||
lang = pythonlocale.normalize(l10n.getTranslationLanguage())
|
lang = locale.normalize(l10n.getTranslationLanguage())
|
||||||
langs = [lang.split(".")[0] + "." + l10n.encoding, lang.split(".")[0] + "." + 'UTF-8', lang]
|
langs = [lang.split(".")[0] + "." + l10n.encoding, lang.split(".")[0] + "." + 'UTF-8', lang]
|
||||||
if 'win32' in sys.platform or 'win64' in sys.platform:
|
if 'win32' in sys.platform or 'win64' in sys.platform:
|
||||||
langs = [l10n.getWindowsLocale(lang)]
|
langs = [l10n.getWindowsLocale(lang)]
|
||||||
for lang in langs:
|
for lang in langs:
|
||||||
try:
|
try:
|
||||||
pythonlocale.setlocale(pythonlocale.LC_ALL, lang)
|
l10n.setlocale(locale.LC_ALL, lang)
|
||||||
if 'win32' not in sys.platform and 'win64' not in sys.platform:
|
if 'win32' not in sys.platform and 'win64' not in sys.platform:
|
||||||
l10n.encoding = pythonlocale.nl_langinfo(pythonlocale.CODESET)
|
l10n.encoding = locale.nl_langinfo(locale.CODESET)
|
||||||
else:
|
else:
|
||||||
l10n.encoding = pythonlocale.getlocale()[1]
|
l10n.encoding = locale.getlocale()[1]
|
||||||
logger.info("Successfully set locale to %s", lang)
|
logger.info("Successfully set locale to %s", lang)
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import shared
|
import shared
|
||||||
|
@ -78,6 +79,11 @@ if time_format != DEFAULT_TIME_FORMAT:
|
||||||
time_format = DEFAULT_TIME_FORMAT
|
time_format = DEFAULT_TIME_FORMAT
|
||||||
encoding = DEFAULT_ENCODING
|
encoding = DEFAULT_ENCODING
|
||||||
|
|
||||||
|
def setlocale(category, newlocale):
|
||||||
|
locale.setlocale(category, newlocale)
|
||||||
|
# it looks like some stuff isn't initialised yet when this is called the
|
||||||
|
# first time and its init gets the locale settings from the environment
|
||||||
|
os.environ["LC_ALL"] = newlocale
|
||||||
|
|
||||||
def formatTimestamp(timestamp = None, as_unicode = True):
|
def formatTimestamp(timestamp = None, as_unicode = True):
|
||||||
#For some reason some timestamps are strings so we need to sanitize.
|
#For some reason some timestamps are strings so we need to sanitize.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user