Skip to content

Commit f25a351

Browse files
Huanxuan AoDean Troyer
authored andcommitted
Fix missing i18n supports in api/ and shell.py
Change-Id: I28d79d7f44b27d2b600dedad2a3601180650ad83 Partial-bug: #1574965
1 parent 769baf3 commit f25a351

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

openstackclient/api/api.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from keystoneauth1 import session as ks_session
2020
from osc_lib import exceptions
2121

22+
from openstackclient.i18n import _
23+
2224

2325
class KeystoneSession(object):
2426
"""Wrapper for the Keystone Session
@@ -254,18 +256,24 @@ def getlist(kw):
254256
if len(data) == 1:
255257
return data[0]
256258
if len(data) > 1:
257-
msg = "Multiple %s exist with %s='%s'"
259+
msg = _("Multiple %(resource)s exist with %(attr)s='%(value)s'")
258260
raise exceptions.CommandError(
259-
msg % (resource, attr, value),
261+
msg % {'resource': resource,
262+
'attr': attr,
263+
'value': value}
260264
)
261265

262266
# Search by id
263267
kwargs = {'id': value}
264268
data = getlist(kwargs)
265269
if len(data) == 1:
266270
return data[0]
267-
msg = "No %s with a %s or ID of '%s' found"
268-
raise exceptions.CommandError(msg % (resource, attr, value))
271+
msg = _("No %(resource)s with a %(attr)s or ID of '%(value)s' found")
272+
raise exceptions.CommandError(
273+
msg % {'resource': resource,
274+
'attr': attr,
275+
'value': value}
276+
)
269277

270278
def find_bulk(
271279
self,
@@ -313,10 +321,10 @@ def find_one(
313321
bulk_list = self.find_bulk(path, **kwargs)
314322
num_bulk = len(bulk_list)
315323
if num_bulk == 0:
316-
msg = "none found"
324+
msg = _("none found")
317325
raise exceptions.NotFound(msg)
318326
elif num_bulk > 1:
319-
msg = "many found"
327+
msg = _("many found")
320328
raise RuntimeError(msg)
321329
return bulk_list[0]
322330

@@ -343,7 +351,7 @@ def find(
343351
try:
344352
ret = self.find_one("/%s/detail" % (path), **kwargs)
345353
except ks_exceptions.NotFound:
346-
msg = "%s not found" % value
354+
msg = _("%s not found") % value
347355
raise exceptions.NotFound(msg)
348356

349357
return ret

openstackclient/api/auth.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True):
171171
'auth.url'))
172172

173173
if msgs:
174-
raise exc.CommandError('Missing parameter(s): \n%s' % '\n'.join(msgs))
174+
raise exc.CommandError(
175+
_('Missing parameter(s): \n%s') % '\n'.join(msgs))
175176

176177

177178
def build_auth_plugins_option_parser(parser):
@@ -187,10 +188,9 @@ def build_auth_plugins_option_parser(parser):
187188
metavar='<auth-type>',
188189
dest='auth_type',
189190
default=utils.env('OS_AUTH_TYPE'),
190-
help='Select an authentication type. Available types: ' +
191-
', '.join(available_plugins) +
192-
'. Default: selected based on --os-username/--os-token' +
193-
' (Env: OS_AUTH_TYPE)',
191+
help=_('Select an authentication type. Available types: %s.'
192+
' Default: selected based on --os-username/--os-token'
193+
' (Env: OS_AUTH_TYPE)') % ', '.join(available_plugins),
194194
choices=available_plugins
195195
)
196196
# Maintain compatibility with old tenant env vars
@@ -215,10 +215,10 @@ def build_auth_plugins_option_parser(parser):
215215
OPTIONS_LIST[o]['env'],
216216
utils.env(OPTIONS_LIST[o]['env']),
217217
),
218-
help='%s\n(Env: %s)' % (
219-
OPTIONS_LIST[o]['help'],
220-
OPTIONS_LIST[o]['env'],
221-
),
218+
help=_('%(help)s\n(Env: %(env)s)') % {
219+
'help': OPTIONS_LIST[o]['help'],
220+
'env': OPTIONS_LIST[o]['env'],
221+
},
222222
)
223223
# add tenant-related options for compatibility
224224
# this is deprecated but still used in some tempest tests...

openstackclient/api/auth_plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from keystoneauth1.loading._plugins import admin_token as token_endpoint
2222
from keystoneauth1.loading._plugins.identity import generic as ksa_password
2323

24+
from openstackclient.i18n import _
25+
2426
LOG = logging.getLogger(__name__)
2527

2628

@@ -51,10 +53,10 @@ def get_options(self):
5153
options.extend([
5254
# Maintain name 'url' for compatibility
5355
cfg.StrOpt('url',
54-
help='Specific service endpoint to use'),
56+
help=_('Specific service endpoint to use')),
5557
cfg.StrOpt('token',
5658
secret=True,
57-
help='Authentication token to use'),
59+
help=_('Authentication token to use')),
5860
])
5961

6062
return options

openstackclient/shell.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import openstackclient
3737
from openstackclient.common import clientmanager
3838
from openstackclient.common import commandmanager
39+
from openstackclient.i18n import _
3940

4041
from os_client_config import config as cloud_config
4142

@@ -63,9 +64,8 @@ def prompt_for_password(prompt=None):
6364
pass
6465
# No password because we did't have a tty or nothing was entered
6566
if not pw:
66-
raise exc.CommandError(
67-
"No password entered, or found via --os-password or OS_PASSWORD",
68-
)
67+
raise exc.CommandError(_("No password entered, or found via"
68+
" --os-password or OS_PASSWORD"),)
6969
return pw
7070

7171

@@ -185,45 +185,49 @@ def build_option_parser(self, description, version):
185185
metavar='<cloud-config-name>',
186186
dest='cloud',
187187
default=utils.env('OS_CLOUD'),
188-
help='Cloud name in clouds.yaml (Env: OS_CLOUD)',
188+
help=_('Cloud name in clouds.yaml (Env: OS_CLOUD)'),
189189
)
190190
# Global arguments
191191
parser.add_argument(
192192
'--os-region-name',
193193
metavar='<auth-region-name>',
194194
dest='region_name',
195195
default=utils.env('OS_REGION_NAME'),
196-
help='Authentication region name (Env: OS_REGION_NAME)')
196+
help=_('Authentication region name (Env: OS_REGION_NAME)'),
197+
)
197198
parser.add_argument(
198199
'--os-cacert',
199200
metavar='<ca-bundle-file>',
200201
dest='cacert',
201202
default=utils.env('OS_CACERT'),
202-
help='CA certificate bundle file (Env: OS_CACERT)')
203+
help=_('CA certificate bundle file (Env: OS_CACERT)'),
204+
)
203205
parser.add_argument(
204206
'--os-cert',
205207
metavar='<certificate-file>',
206208
dest='cert',
207209
default=utils.env('OS_CERT'),
208-
help='Client certificate bundle file (Env: OS_CERT)')
210+
help=_('Client certificate bundle file (Env: OS_CERT)'),
211+
)
209212
parser.add_argument(
210213
'--os-key',
211214
metavar='<key-file>',
212215
dest='key',
213216
default=utils.env('OS_KEY'),
214-
help='Client certificate key file (Env: OS_KEY)')
217+
help=_('Client certificate key file (Env: OS_KEY)'),
218+
)
215219
verify_group = parser.add_mutually_exclusive_group()
216220
verify_group.add_argument(
217221
'--verify',
218222
action='store_true',
219223
default=None,
220-
help='Verify server certificate (default)',
224+
help=_('Verify server certificate (default)'),
221225
)
222226
verify_group.add_argument(
223227
'--insecure',
224228
action='store_true',
225229
default=None,
226-
help='Disable server certificate verification',
230+
help=_('Disable server certificate verification'),
227231
)
228232
parser.add_argument(
229233
'--os-default-domain',
@@ -232,28 +236,29 @@ def build_option_parser(self, description, version):
232236
default=utils.env(
233237
'OS_DEFAULT_DOMAIN',
234238
default=DEFAULT_DOMAIN),
235-
help='Default domain ID, default=' +
236-
DEFAULT_DOMAIN +
237-
' (Env: OS_DEFAULT_DOMAIN)')
239+
help=_('Default domain ID, default=%s. '
240+
'(Env: OS_DEFAULT_DOMAIN)') % DEFAULT_DOMAIN,
241+
)
238242
parser.add_argument(
239243
'--os-interface',
240244
metavar='<interface>',
241245
dest='interface',
242246
choices=['admin', 'public', 'internal'],
243247
default=utils.env('OS_INTERFACE'),
244-
help='Select an interface type.'
245-
' Valid interface types: [admin, public, internal].'
246-
' (Env: OS_INTERFACE)')
248+
help=_('Select an interface type.'
249+
' Valid interface types: [admin, public, internal].'
250+
' (Env: OS_INTERFACE)'),
251+
)
247252
parser.add_argument(
248253
'--timing',
249254
default=False,
250255
action='store_true',
251-
help="Print API call timing info",
256+
help=_("Print API call timing info"),
252257
)
253258
parser.add_argument(
254259
'--os-beta-command',
255260
action='store_true',
256-
help="Enable beta commands which are subject to change",
261+
help=_("Enable beta commands which are subject to change"),
257262
)
258263

259264
# osprofiler HMAC key argument
@@ -262,7 +267,7 @@ def build_option_parser(self, description, version):
262267
'--os-profile',
263268
metavar='hmac-key',
264269
dest='profile',
265-
help='HMAC key for encrypting profiling context data',
270+
help=_('HMAC key for encrypting profiling context data'),
266271
)
267272
# NOTE(dtroyer): This global option should have been named
268273
# --os-profile as --profile interferes with at

0 commit comments

Comments
 (0)