summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2014-06-10 06:36:28 -0700
committerDoug Hellmann <doug.hellmann@dreamhost.com>2014-06-18 06:42:16 -0700
commitc4dd244ff3d33a183a76ca78f87a9795223ff4e8 (patch)
tree9ea010f12c6bc49788db4bd8a4401e8ab1d5bcd9
parenta92f897ebc92efaad79eb1fddadaeb366aae2160 (diff)
downloadoslo-i18n-c4dd244ff3d33a183a76ca78f87a9795223ff4e8.tar.gz
Build locale dir env var name consistently
Use get_locale_dir_variable_name to build the environment variable in get_available_languages() and Message._translate_msgid(). Change-Id: I660debd0680f2c2e29b62c5d6c1bbe29b308b695
-rw-r--r--oslo/i18n/_message.py5
-rw-r--r--oslo/i18n/gettextutils.py12
2 files changed, 10 insertions, 7 deletions
diff --git a/oslo/i18n/_message.py b/oslo/i18n/_message.py
index 93374a4..534c273 100644
--- a/oslo/i18n/_message.py
+++ b/oslo/i18n/_message.py
@@ -23,6 +23,7 @@ import os
import six
+from oslo.i18n import _locale
from oslo.i18n import _translate
@@ -91,7 +92,9 @@ class Message(six.text_type):
# If the system locale is not available to the runtime use English
desired_locale = system_locale[0] or 'en_US'
- locale_dir = os.environ.get(domain.upper() + '_LOCALEDIR')
+ locale_dir = os.environ.get(
+ _locale.get_locale_dir_variable_name(domain)
+ )
lang = gettext.translation(domain,
localedir=locale_dir,
languages=[desired_locale],
diff --git a/oslo/i18n/gettextutils.py b/oslo/i18n/gettextutils.py
index 38f78eb..6600892 100644
--- a/oslo/i18n/gettextutils.py
+++ b/oslo/i18n/gettextutils.py
@@ -27,6 +27,7 @@ import six
# Expose a few internal pieces as part of our public API.
from oslo.i18n._factory import TranslatorFactory # noqa
from oslo.i18n._lazy import enable_lazy # noqa
+from oslo.i18n import _locale
from oslo.i18n._translate import translate # noqa
@@ -61,14 +62,13 @@ def get_available_languages(domain):
:param domain: the domain to get languages for
"""
- def find(language, domain, localedir):
- return gettext.find(domain, localedir=os.environ.get(localedir),
- languages=[language])
-
if domain in _AVAILABLE_LANGUAGES:
return copy.copy(_AVAILABLE_LANGUAGES[domain])
- localedir = '%s_LOCALEDIR' % domain.upper()
+ localedir = os.environ.get(_locale.get_locale_dir_variable_name(domain))
+ find = lambda x: gettext.find(domain,
+ localedir=localedir,
+ languages=[x])
# NOTE(mrodden): en_US should always be available (and first in case
# order matters) since our in-line message strings are en_US
@@ -82,7 +82,7 @@ def get_available_languages(domain):
locale_identifiers = list_identifiers()
language_list.extend(language for language in locale_identifiers
- if find(language, domain, localedir))
+ if find(language))
# NOTE(luisg): Babel>=1.0,<1.3 has a bug where some OpenStack supported
# locales (e.g. 'zh_CN', and 'zh_TW') aren't supported even though they