Make oslo.i18n an optional dependency

In an ideal world we would have all messages translated to at least major
languages. In reality, ironic has never boasted a great set of translation,
and according to Zanata only 2.94% of messages are translated for ironic
in Train (1.33% for ironic-inspector). Given that ironic-python-agent is
not translated at all, using i18n by default seems an overkill.

Change-Id: I12287c6b7208af487cc9eee825ae7f38ec707d91
This commit is contained in:
Dmitry Tantsur 2020-04-02 14:10:21 +02:00
parent 9f93694b9a
commit 1d9c8283b8
6 changed files with 24 additions and 7 deletions

View File

@ -14,10 +14,10 @@
import sys import sys
from oslo_config import cfg from oslo_config import cfg
import oslo_i18n as i18n
from oslo_log import log from oslo_log import log
from ironic.api import app from ironic.api import app
from ironic.common import i18n
from ironic.common import service from ironic.common import service

View File

@ -25,6 +25,6 @@ import eventlet
eventlet.monkey_patch(os=False) eventlet.monkey_patch(os=False)
import oslo_i18n as i18n # noqa for I202 due to 'import eventlet' above from ironic.common import i18n # noqa for I202 due to 'import eventlet' above
i18n.install('ironic') i18n.install('ironic')

View File

@ -19,9 +19,20 @@ See https://docs.openstack.org/oslo.i18n/latest/user/
""" """
try:
import oslo_i18n as i18n import oslo_i18n as i18n
except ImportError:
def _(msg):
return msg
def install(domain):
# NOTE(dtantsur): this is called before logging is initialized, so we
# cannot really log a warning here.
pass
else:
_translators = i18n.TranslatorFactory(domain='ironic') _translators = i18n.TranslatorFactory(domain='ironic')
# The primary translation function using the well-known name "_" # The primary translation function using the well-known name "_"
_ = _translators.primary _ = _translators.primary
install = i18n.install

View File

@ -0,0 +1,5 @@
---
upgrade:
- |
The dependency on ``oslo.i18n`` is now optional. If you would like messages
from ironic to be translated, you need to install it explicitly.

View File

@ -21,7 +21,6 @@ oslo.config>=5.2.0 # Apache-2.0
oslo.context>=2.19.2 # Apache-2.0 oslo.context>=2.19.2 # Apache-2.0
oslo.db>=4.40.0 # Apache-2.0 oslo.db>=4.40.0 # Apache-2.0
oslo.rootwrap>=5.8.0 # Apache-2.0 oslo.rootwrap>=5.8.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.log>=3.36.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0
oslo.middleware>=3.31.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0
oslo.policy>=1.30.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0

View File

@ -200,3 +200,5 @@ universal = 1
[extras] [extras]
guru_meditation_reports = guru_meditation_reports =
oslo.reports>=1.18.0 # Apache-2.0 oslo.reports>=1.18.0 # Apache-2.0
i18n =
oslo.i18n>=3.15.3 # Apache-2.0