Use oslo.i18n
Replace initialization of gettext / oslo-incubator's gettextutils with oslo.i18n lib initialization. Implements blueprint sahara-oslo-i18n Change-Id: I6626cc22c7d38c0074930e5baf7866ff1dd04028
This commit is contained in:
parent
bdac970830
commit
a5b15fb04a
@ -18,13 +18,12 @@
|
||||
from sahara.utils import patches
|
||||
patches.patch_all()
|
||||
|
||||
import gettext
|
||||
import os
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
from eventlet import wsgi
|
||||
from oslo.config import cfg
|
||||
from oslo import i18n
|
||||
|
||||
|
||||
# If ../sahara/__init__.py exists, add ../ to Python search path, so that
|
||||
@ -37,7 +36,11 @@ if os.path.exists(os.path.join(possible_topdir,
|
||||
'__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
gettext.install('sahara', unicode=1)
|
||||
|
||||
# NOTE(slukjanov): i18n.enable_lazy() must be called before
|
||||
# sahara.utils.i18n._() is called to ensure it has the desired
|
||||
# lazy lookup behavior.
|
||||
i18n.enable_lazy()
|
||||
|
||||
|
||||
import sahara.main as server
|
||||
@ -55,5 +58,6 @@ def main():
|
||||
server.setup_sahara_api('all-in-one')
|
||||
server.setup_sahara_engine()
|
||||
|
||||
from oslo.config import cfg
|
||||
wsgi.server(eventlet.listen((cfg.CONF.host, cfg.CONF.port), backlog=500),
|
||||
app, log=logging.WritableLogger(LOG), debug=False)
|
||||
|
@ -18,13 +18,12 @@
|
||||
from sahara.utils import patches
|
||||
patches.patch_all()
|
||||
|
||||
import gettext
|
||||
import os
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
from eventlet import wsgi
|
||||
from oslo.config import cfg
|
||||
from oslo import i18n
|
||||
|
||||
|
||||
# If ../sahara/__init__.py exists, add ../ to Python search path, so that
|
||||
@ -37,7 +36,11 @@ if os.path.exists(os.path.join(possible_topdir,
|
||||
'__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
gettext.install('sahara', unicode=1)
|
||||
|
||||
# NOTE(slukjanov): i18n.enable_lazy() must be called before
|
||||
# sahara.utils.i18n._() is called to ensure it has the desired
|
||||
# lazy lookup behavior.
|
||||
i18n.enable_lazy()
|
||||
|
||||
|
||||
import sahara.main as server
|
||||
@ -54,5 +57,6 @@ def main():
|
||||
|
||||
server.setup_sahara_api('distributed')
|
||||
|
||||
from oslo.config import cfg
|
||||
wsgi.server(eventlet.listen((cfg.CONF.host, cfg.CONF.port), backlog=500),
|
||||
app, log=logging.WritableLogger(LOG), debug=False)
|
||||
|
@ -18,10 +18,11 @@
|
||||
from sahara.utils import patches
|
||||
patches.patch_all()
|
||||
|
||||
import gettext
|
||||
import os
|
||||
import sys
|
||||
|
||||
from oslo import i18n
|
||||
|
||||
|
||||
# If ../sahara/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
@ -33,7 +34,11 @@ if os.path.exists(os.path.join(possible_topdir,
|
||||
'__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
gettext.install('sahara', unicode=1)
|
||||
|
||||
# NOTE(slukjanov): i18n.enable_lazy() must be called before
|
||||
# sahara.utils.i18n._() is called to ensure it has the desired
|
||||
# lazy lookup behavior.
|
||||
i18n.enable_lazy()
|
||||
|
||||
|
||||
import sahara.main as server
|
||||
|
54
sahara/i18n.py
Normal file
54
sahara/i18n.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# It's based on oslo.i18n usage in OpenStack Keystone project and
|
||||
# recommendations from http://docs.openstack.org/developer/oslo.i18n/usage.html
|
||||
|
||||
from oslo import i18n
|
||||
|
||||
|
||||
_translators = i18n.TranslatorFactory(domain='sahara')
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# Due to the fact that some modules in oslo-incubator synced to the
|
||||
# sahara/openstack/common are using its own gettextutils we're monkey patching
|
||||
# our copy of oslo-incubator's gettextutils to use our initialized oslo.i18n
|
||||
# versions.
|
||||
|
||||
# FIXME(slukjanov): Remove the monkey patch when oslo-incubator will fully use
|
||||
# oslo.i18n and this code will be synced to sahara. The
|
||||
# sahara/openstack/common/gettextutils.py after that
|
||||
|
||||
from sahara.openstack.common import gettextutils
|
||||
|
||||
|
||||
gettextutils._ = _
|
||||
gettextutils._LI = _LI
|
||||
gettextutils._LW = _LW
|
||||
gettextutils._LE = _LE
|
||||
gettextutils._LC = _LC
|
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from oslo import i18n
|
||||
|
||||
# NOTE(slukjanov): i18n.enable_lazy() must be called before
|
||||
# sahara.utils.i18n._() is called to ensure it has the desired
|
||||
# lazy lookup behavior.
|
||||
i18n.enable_lazy()
|
Loading…
Reference in New Issue
Block a user