l10n quality fixes
This commit is contained in:
parent
afce500085
commit
1181db66e0
26
src/l10n.py
26
src/l10n.py
|
@ -1,4 +1,6 @@
|
||||||
|
"""
|
||||||
|
Localization
|
||||||
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
@ -78,13 +80,17 @@ 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):
|
def setlocale(category, newlocale):
|
||||||
|
"""Set the locale"""
|
||||||
locale.setlocale(category, newlocale)
|
locale.setlocale(category, newlocale)
|
||||||
# it looks like some stuff isn't initialised yet when this is called the
|
# 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
|
# first time and its init gets the locale settings from the environment
|
||||||
os.environ["LC_ALL"] = newlocale
|
os.environ["LC_ALL"] = newlocale
|
||||||
|
|
||||||
|
|
||||||
def formatTimestamp(timestamp=None, as_unicode=True):
|
def formatTimestamp(timestamp=None, as_unicode=True):
|
||||||
|
"""Return a formatted timestamp"""
|
||||||
# For some reason some timestamps are strings so we need to sanitize.
|
# For some reason some timestamps are strings so we need to sanitize.
|
||||||
if timestamp is not None and not isinstance(timestamp, int):
|
if timestamp is not None and not isinstance(timestamp, int):
|
||||||
try:
|
try:
|
||||||
|
@ -109,17 +115,21 @@ def formatTimestamp(timestamp = None, as_unicode = True):
|
||||||
return unicode(timestring, encoding)
|
return unicode(timestring, encoding)
|
||||||
return timestring
|
return timestring
|
||||||
|
|
||||||
|
|
||||||
def getTranslationLanguage():
|
def getTranslationLanguage():
|
||||||
userlocale = None
|
"""Return the user's language choice"""
|
||||||
if BMConfigParser().has_option('bitmessagesettings', 'userlocale'):
|
userlocale = BMConfigParser().safeGet(
|
||||||
userlocale = BMConfigParser().get('bitmessagesettings', 'userlocale')
|
'bitmessagesettings', 'userlocale', 'system')
|
||||||
|
return userlocale if userlocale and userlocale != 'system' else language
|
||||||
|
|
||||||
if userlocale in [None, '', 'system']:
|
|
||||||
return language
|
|
||||||
|
|
||||||
return userlocale
|
|
||||||
|
|
||||||
def getWindowsLocale(posixLocale):
|
def getWindowsLocale(posixLocale):
|
||||||
|
"""
|
||||||
|
Get the Windows locale
|
||||||
|
Technically this converts the locale string from UNIX to Windows format,
|
||||||
|
because they use different ones in their
|
||||||
|
libraries. E.g. "en_EN.UTF-8" to "english".
|
||||||
|
"""
|
||||||
if posixLocale in windowsLanguageMap:
|
if posixLocale in windowsLanguageMap:
|
||||||
return windowsLanguageMap[posixLocale]
|
return windowsLanguageMap[posixLocale]
|
||||||
if "." in posixLocale:
|
if "." in posixLocale:
|
||||||
|
|
Reference in New Issue
Block a user