use gettext

This commit is contained in:
Emmanuel Garette 2019-04-09 07:28:11 +02:00 committed by Emmanuel Garette
parent 5725bdf3b7
commit dd14b0f752
2 changed files with 7 additions and 6 deletions

View file

@ -1,4 +1,4 @@
from .tiramisu_cmdline_parser import TiramisuCmdlineParser from .api import TiramisuCmdlineParser
__version__ = "0.0.1" __version__ = "0.0.1"
__all__ = ('TiramisuCmdlineParser',) __all__ = ('TiramisuCmdlineParser',)

View file

@ -15,6 +15,7 @@
from typing import Union, List, Optional from typing import Union, List, Optional
from argparse import ArgumentParser, Namespace, SUPPRESS, _HelpAction, HelpFormatter from argparse import ArgumentParser, Namespace, SUPPRESS, _HelpAction, HelpFormatter
from copy import copy from copy import copy
from gettext import gettext as _
try: try:
@ -139,13 +140,13 @@ class TiramisuCmdlineParser(ArgumentParser):
if args == ('-h', '--help'): if args == ('-h', '--help'):
super().add_argument(*args, **kwargs) super().add_argument(*args, **kwargs)
else: else:
raise NotImplementedError('do not use add_argument') raise NotImplementedError(_('do not use add_argument'))
def add_arguments(self, *args, **kwargs): def add_arguments(self, *args, **kwargs):
raise NotImplementedError('do not use add_argument') raise NotImplementedError(_('do not use add_argument'))
def add_subparsers(self, *args, **kwargs): def add_subparsers(self, *args, **kwargs):
raise NotImplementedError('do not use add_subparsers') raise NotImplementedError(_('do not use add_subparsers'))
def _gen_argument(self, name, longargument, no_prefix=False): def _gen_argument(self, name, longargument, no_prefix=False):
shortarg = len(name) == 1 and not longargument shortarg = len(name) == 1 and not longargument
@ -186,7 +187,7 @@ class TiramisuCmdlineParser(ArgumentParser):
continue continue
name = option.name() name = option.name()
if name.startswith(self.prefix_chars): if name.startswith(self.prefix_chars):
raise ValueError('name cannot startswith "{}"'.format(self.prefix_chars)) raise ValueError(_('name cannot startswith "{}"').format(self.prefix_chars))
if self.fullpath and prefix: if self.fullpath and prefix:
name = prefix + '.' + name name = prefix + '.' + name
properties = obj.property.get() properties = obj.property.get()
@ -206,7 +207,7 @@ class TiramisuCmdlineParser(ArgumentParser):
else: else:
if 'positional' in properties: if 'positional' in properties:
if option.type() == 'boolean': if option.type() == 'boolean':
raise ValueError('boolean option must not be positional') raise ValueError(_('boolean option must not be positional'))
# if not 'mandatory' in properties: # if not 'mandatory' in properties:
# raise ValueError('"positional" argument must be "mandatory" too') # raise ValueError('"positional" argument must be "mandatory" too')
args = [option.path()] args = [option.path()]