summaryrefslogtreecommitdiff
path: root/oslo/i18n/_message.py
diff options
context:
space:
mode:
authorJuan Antonio Osorio <juan.osorio.robles@ericsson.com>2014-06-06 17:28:52 +0300
committerJuan Antonio Osorio <juan.osorio.robles@ericsson.com>2014-06-11 09:17:51 +0300
commita92f897ebc92efaad79eb1fddadaeb366aae2160 (patch)
tree3d38e23392228d1397b63cd969bf651e6d02c97d /oslo/i18n/_message.py
parent3779302aa1a0ebb0e6ad68852281fd9f2fba975c (diff)
downloadoslo-i18n-a92f897ebc92efaad79eb1fddadaeb366aae2160.tar.gz
Trivial refactors for gettextutils
* Favor one-line conditional assignments instead of more verbose assignments inside if...else clauses * Favor the usage of generators instead of explicit for loops for perfomance Change-Id: Idfbbec7cd2efa1ebbf5111abb24cb147edb176ee
Diffstat (limited to 'oslo/i18n/_message.py')
-rw-r--r--oslo/i18n/_message.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/oslo/i18n/_message.py b/oslo/i18n/_message.py
index 73cb7bf..93374a4 100644
--- a/oslo/i18n/_message.py
+++ b/oslo/i18n/_message.py
@@ -89,20 +89,14 @@ class Message(six.text_type):
if not desired_locale:
system_locale = locale.getdefaultlocale()
# If the system locale is not available to the runtime use English
- if not system_locale[0]:
- desired_locale = 'en_US'
- else:
- desired_locale = system_locale[0]
+ desired_locale = system_locale[0] or 'en_US'
locale_dir = os.environ.get(domain.upper() + '_LOCALEDIR')
lang = gettext.translation(domain,
localedir=locale_dir,
languages=[desired_locale],
fallback=True)
- if six.PY3:
- translator = lang.gettext
- else:
- translator = lang.ugettext
+ translator = lang.gettext if six.PY3 else lang.ugettext
translated_message = translator(msgid)
return translated_message
@@ -135,10 +129,10 @@ class Message(six.text_type):
# Copy each item in case one does not support deep copy.
params = {}
if isinstance(self.params, dict):
- for key, val in self.params.items():
- params[key] = self._copy_param(val)
- for key, val in other.items():
- params[key] = self._copy_param(val)
+ params.update((key, self._copy_param(val))
+ for key, val in self.params.items())
+ params.update((key, self._copy_param(val))
+ for key, val in other.items())
else:
params = self._copy_param(other)
return params