Improve language detection. (Not tested yet.)

This commit is contained in:
Ian Walton 2020-08-10 08:29:16 -04:00
parent 0b422624fd
commit d5835f027d

View File

@ -1,5 +1,6 @@
import gettext
import builtins
import locale
from .conf import settings
@ -10,9 +11,19 @@ def configure():
global translation
from .utils import get_resource
messages_dir = get_resource("messages")
lang = None
if settings.lang is not None:
translation = gettext.translation("base", messages_dir, languages=[settings.lang], fallback=True)
lang = settings.lang
else:
# This is more robust than the built-in language detection in gettext.
# Specifically, it supports Windows correctly.
lc = locale.getdefaultlocale()
if lc is not None and lc[0] is not None:
lang = lc[0]
if lang is not None:
translation = gettext.translation("base", messages_dir, languages=[lang], fallback=True)
else:
translation = gettext.translation("base", messages_dir, fallback=True)