Support i18n messages in config generator
if opt.help is i18n'ed then we land up in trouble since Message objects do not support addition and a TypeError gets thrown. So we just use a better way to construct the string to avoid the TypeError. Closes-Bug: #1408032 Change-Id: If1feb65c6467f1c8176369f49d128c172c569c66
This commit is contained in:
parent
035636ddd6
commit
ea815b3304
@ -186,7 +186,11 @@ class _OptFormatter(object):
|
||||
|
||||
opt_type = self._TYPE_DESCRIPTIONS.get(type(opt), 'unknown type')
|
||||
|
||||
help_text = u'%s(%s)' % (opt.help + ' ' if opt.help else '', opt_type)
|
||||
if opt.help:
|
||||
help_text = u'%s (%s)' % (opt.help,
|
||||
opt_type)
|
||||
else:
|
||||
help_text = u'(%s)' % opt_type
|
||||
lines = self._format_help(help_text)
|
||||
|
||||
for d in opt.deprecated_opts:
|
||||
|
@ -21,5 +21,8 @@ coverage>=3.6
|
||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||
oslosphinx>=2.2.0 # Apache-2.0
|
||||
|
||||
# Required only for tests
|
||||
oslo.i18n>=1.3.0 # Apache-2.0
|
||||
|
||||
# mocking framework
|
||||
mock>=1.0
|
||||
|
@ -23,6 +23,7 @@ import testscenarios
|
||||
from oslo.config import cfg
|
||||
from oslo.config import fixture as config_fixture
|
||||
from oslo.config import generator
|
||||
from oslo.i18n import fixture as i18n_fixture
|
||||
|
||||
load_tests = testscenarios.load_tests_apply_scenarios
|
||||
|
||||
@ -31,6 +32,9 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||
|
||||
opts = {
|
||||
'foo': cfg.StrOpt('foo', help='foo option'),
|
||||
'foo_i18n_help': cfg.StrOpt('foo_i18n_help',
|
||||
help=i18n_fixture.Translation().lazy(
|
||||
'this is a lazy message')),
|
||||
'bar': cfg.StrOpt('bar', help='bar option'),
|
||||
'foo-bar': cfg.StrOpt('foo-bar', help='foobar'),
|
||||
'no_help': cfg.StrOpt('no_help'),
|
||||
@ -206,6 +210,17 @@ class GeneratorTestCase(base.BaseTestCase):
|
||||
|
||||
# foobar (string value)
|
||||
#foo_bar = <None>
|
||||
''')),
|
||||
('i18n_help',
|
||||
dict(opts=[('test', [(None, [opts['foo_i18n_help']])])],
|
||||
expected='''[DEFAULT]
|
||||
|
||||
#
|
||||
# From test
|
||||
#
|
||||
|
||||
# this is a lazy message (string value)
|
||||
#foo_i18n_help = <None>
|
||||
''')),
|
||||
('no_help',
|
||||
dict(opts=[('test', [(None, [opts['no_help']])])],
|
||||
|
Loading…
x
Reference in New Issue
Block a user