summaryrefslogtreecommitdiff
path: root/nova/i18n.py
diff options
context:
space:
mode:
authorDavanum Srinivas <dims@linux.vnet.ibm.com>2014-07-11 21:03:15 -0400
committerDavanum Srinivas <dims@linux.vnet.ibm.com>2014-07-18 14:28:09 -0400
commit826aed0ec7e59d52d515a86569b6e23b08c6c072 (patch)
treec40caa265d563310db5fb64d2247486cfa732e81 /nova/i18n.py
parentff756a0184806a30902d5e68a8f30345b54a6ed1 (diff)
downloadnova-826aed0ec7e59d52d515a86569b6e23b08c6c072.tar.gz
Use oslo.i18n
oslo.i18n provides the i18n functions that were provided by oslo-incubator's gettextutils module. Some tests that were using internal details of the library were removed. Change-Id: I44cfd5552e0dd86af21073419d31622f5fdb28e0
Diffstat (limited to 'nova/i18n.py')
-rw-r--r--nova/i18n.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/nova/i18n.py b/nova/i18n.py
new file mode 100644
index 0000000000..e3e5673398
--- /dev/null
+++ b/nova/i18n.py
@@ -0,0 +1,66 @@
+# Copyright 2014 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""oslo.i18n integration module.
+
+See http://docs.openstack.org/developer/oslo.i18n/usage.html .
+
+"""
+
+from oslo import i18n
+
+from nova.openstack.common import gettextutils
+
+DOMAIN = 'nova'
+
+_translators = i18n.TranslatorFactory(domain=DOMAIN)
+
+# The primary translation function using the well-known name "_"
+_ = _translators.primary
+
+# Translators for log levels.
+#
+# The abbreviated names are meant to reflect the usual use of a short
+# name like '_'. The "L" is for "log" and the other letter comes from
+# the level.
+_LI = _translators.log_info
+_LW = _translators.log_warning
+_LE = _translators.log_error
+_LC = _translators.log_critical
+
+
+def translate(value, user_locale):
+ return i18n.translate(value, user_locale)
+
+
+def get_available_languages():
+ return i18n.get_available_languages(DOMAIN)
+
+
+# Parts in oslo-incubator are still using gettextutils._(), _LI(), etc., from
+# oslo-incubator. Until these parts are changed to use oslo.i18n, Keystone
+# needs to do something to allow them to work. One option is to continue to
+# initialize gettextutils, but with the way that Nova has initialization
+# spread out over mutltiple entry points, we'll monkey-patch
+# gettextutils._(), _LI(), etc., to use our oslo.i18n versions.
+
+# FIXME(dims): Remove the monkey-patching and update openstack-common.conf and
+# do a sync with oslo-incubator to remove gettextutils once oslo-incubator
+# isn't using oslo-incubator gettextutils any more.
+
+gettextutils._ = _
+gettextutils._LI = _LI
+gettextutils._LW = _LW
+gettextutils._LE = _LE
+gettextutils._LC = _LC