Commit 0e9f8f9d authored by Hugo Posnic's avatar Hugo Posnic

Simplify i18n.py

parent 42fac274
......@@ -26,39 +26,27 @@ import gettext
# @LOCALE_DIR@/@LANGUAGE@/LC_MESSAGES/@APP_NAME@.mo
APP_NAME = "pacman_mirrors"
APP_DIR = os.path.join(sys.prefix,
"share")
APP_DIR = os.path.join(sys.prefix, "share")
LOCALE_DIR = os.path.join(APP_DIR, "locale")
# Now we need to choose the language. We will provide a list, and gettext
# will use the first translation available in the list
DEFAULT_LANGUAGES = os.environ.get("LANG", "").split(":")
DEFAULT_LANGUAGES += ["en_US"]
# Try to get the languages from the default locale
languages = []
LANGUAGES = []
try:
lc, encoding = locale.getdefaultlocale()
if lc:
languages = [lc]
user_locale = locale.getdefaultlocale()[0]
if user_locale:
LANGUAGES += user_locale
except ValueError:
pass
# Concat all languages (env + default locale),
# and here we have the languages and location of the translations
languages += DEFAULT_LANGUAGES
mo_location = LOCALE_DIR
LANGUAGES += os.environ.get("LANG", "").split(":")
LANGUAGES += ["en_US"]
# Lets tell those details to gettext
# (nothing to change here for you)
gettext.install(True)
gettext.bindtextdomain(APP_NAME,
mo_location)
gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
gettext.textdomain(APP_NAME)
language = gettext.translation(APP_NAME,
mo_location,
languages=languages,
fallback=True)
language = gettext.translation(APP_NAME, LOCALE_DIR, LANGUAGES, fallback=True)
# Add this to every module:
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment