mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-03 12:11:25 -06:00
Fix translatable strings in ipalib plugins.
Needed for xgettext/pygettext processing.
This commit is contained in:
parent
8145952752
commit
f3de95ce99
@ -118,7 +118,7 @@ False
|
||||
>>> hasattr(api.Command, 'my_command')
|
||||
True
|
||||
>>> api.Command.my_command.doc
|
||||
'My example plugin.'
|
||||
Gettext('My example plugin.', domain='ipa', localedir=None)
|
||||
|
||||
Notice that your plugin instance is accessed through an attribute named
|
||||
``my_command``, the same name as your plugin class name.
|
||||
|
@ -302,7 +302,7 @@ class Param(ReadOnly):
|
||||
('cli_name', str, None),
|
||||
('cli_short_name', str, None),
|
||||
('label', (str, Gettext), None),
|
||||
('doc', (str, Gettext), None),
|
||||
('doc', (basestring, Gettext), None),
|
||||
('required', bool, True),
|
||||
('multivalue', bool, False),
|
||||
('primary_key', bool, False),
|
||||
@ -384,7 +384,7 @@ class Param(ReadOnly):
|
||||
elif type(value) is str:
|
||||
value = frozenset([value])
|
||||
if (
|
||||
type(kind) is type and type(value) is not kind
|
||||
type(kind) is type and not isinstance(value, kind)
|
||||
or
|
||||
type(kind) is tuple and not isinstance(value, kind)
|
||||
):
|
||||
|
@ -38,6 +38,7 @@ import errors
|
||||
from config import Env
|
||||
import util
|
||||
import text
|
||||
from text import _
|
||||
from base import ReadOnly, NameSpace, lock, islocked, check_name
|
||||
from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE
|
||||
|
||||
@ -181,11 +182,12 @@ class Plugin(ReadOnly):
|
||||
self.bases = tuple(
|
||||
'%s.%s' % (b.__module__, b.__name__) for b in cls.__bases__
|
||||
)
|
||||
self.doc = _(inspect.getdoc(cls))
|
||||
if self.doc is None:
|
||||
doc = inspect.getdoc(cls)
|
||||
self.doc = _(doc)
|
||||
if doc is None:
|
||||
self.summary = '<%s>' % self.fullname
|
||||
else:
|
||||
self.summary = self.doc.split('\n\n', 1)[0]
|
||||
self.summary = unicode(self.doc).split('\n\n', 1)[0]
|
||||
log = logging.getLogger(self.fullname)
|
||||
for name in ('debug', 'info', 'warning', 'error', 'critical', 'exception'):
|
||||
if hasattr(self, name):
|
||||
|
@ -329,7 +329,9 @@ class automountlocation_import(LDAPQuery):
|
||||
fp.close()
|
||||
except IOError, e:
|
||||
if e.errno == 2:
|
||||
raise errors.NotFound(reason=_('File %(file)s not found' % {'file':filename}))
|
||||
raise errors.NotFound(
|
||||
reason=_('File %(file)s not found') % {'file': filename}
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
return map
|
||||
|
@ -759,9 +759,12 @@ class LDAPUpdate(LDAPQuery, crud.Update):
|
||||
|
||||
def _get_rename_option(self):
|
||||
rdnparam = getattr(self.obj.params, self.obj.rdnattr)
|
||||
return rdnparam.clone_rename('rename', cli_name='rename',
|
||||
required=False, label=_('Rename'),
|
||||
doc=_('Rename the %s object' % self.obj.object_name))
|
||||
return rdnparam.clone_rename('rename',
|
||||
cli_name='rename', required=False, label=_('Rename'),
|
||||
doc=_('Rename the %(ldap_obj_name)s object') % dict(
|
||||
ldap_obj_name=self.obj.object_name
|
||||
)
|
||||
)
|
||||
|
||||
def get_options(self):
|
||||
for option in super(LDAPUpdate, self).get_options():
|
||||
|
@ -74,8 +74,8 @@ class batch(Command):
|
||||
)
|
||||
|
||||
has_output = (
|
||||
Output('count', int, doc=_('')),
|
||||
Output('results', list, doc=_(''))
|
||||
Output('count', int, doc=''),
|
||||
Output('results', list, doc='')
|
||||
)
|
||||
|
||||
def execute(self, *args, **options):
|
||||
|
@ -221,7 +221,7 @@ class delegation_find(crud.Search):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d delegation matched', '%(count)d delegations matched'
|
||||
'%(count)d delegation matched', '%(count)d delegations matched', 0
|
||||
)
|
||||
|
||||
def execute(self, term, **kw):
|
||||
|
@ -201,7 +201,9 @@ def is_ns_rec_resolvable(name):
|
||||
try:
|
||||
return api.Command['dns_resolve'](name)
|
||||
except errors.NotFound:
|
||||
raise errors.NotFound(reason=_('Nameserver \'%(host)s\' does not have a corresponding A/AAAA record' % {'host':name}))
|
||||
raise errors.NotFound(
|
||||
reason=_('Nameserver \'%(host)s\' does not have a corresponding A/AAAA record') % {'host': name}
|
||||
)
|
||||
|
||||
def add_forward_record(zone, name, str_address):
|
||||
addr = netaddr.IPAddress(str_address)
|
||||
@ -816,7 +818,9 @@ class dns_resolve(Command):
|
||||
break
|
||||
|
||||
if not found:
|
||||
raise errors.NotFound(reason=_('Host \'%(host)s\' not found' % {'host':query}))
|
||||
raise errors.NotFound(
|
||||
reason=_('Host \'%(host)s\' not found') % {'host': query}
|
||||
)
|
||||
|
||||
return dict(result=True, value=query)
|
||||
|
||||
|
@ -316,7 +316,9 @@ class host_add(LDAPCreate):
|
||||
match = True
|
||||
break
|
||||
if not match:
|
||||
raise errors.NotFound(reason=_('DNS zone %(zone)s not found' % dict(zone=domain)))
|
||||
raise errors.NotFound(
|
||||
reason=_('DNS zone %(zone)s not found') % dict(zone=domain)
|
||||
)
|
||||
if not options.get('no_reverse', False):
|
||||
# we prefer lookup of the IP through the reverse zone
|
||||
revzone, revname = get_reverse_zone(options['ip_address'])
|
||||
@ -327,7 +329,9 @@ class host_add(LDAPCreate):
|
||||
match = True
|
||||
break
|
||||
if not match:
|
||||
raise errors.NotFound(reason=_('Reverse DNS zone %(zone)s not found' % dict(zone=revzone)))
|
||||
raise errors.NotFound(
|
||||
reason=_('Reverse DNS zone %(zone)s not found') % dict(zone=revzone)
|
||||
)
|
||||
try:
|
||||
reverse = api.Command['dnsrecord_find'](revzone, idnsname=revname)
|
||||
if reverse['count'] > 0:
|
||||
@ -395,7 +399,9 @@ class host_add(LDAPCreate):
|
||||
# context, don't crash.
|
||||
pass
|
||||
if exc:
|
||||
raise errors.NonFatalError(reason=_('The host was added but the DNS update failed with: %(exc)s' % dict(exc=exc)))
|
||||
raise errors.NonFatalError(
|
||||
reason=_('The host was added but the DNS update failed with: %(exc)s') % dict(exc=exc)
|
||||
)
|
||||
set_certificate_attrs(entry_attrs)
|
||||
return dn
|
||||
|
||||
@ -457,7 +463,9 @@ class host_del(LDAPDelete):
|
||||
match = True
|
||||
break
|
||||
if not match:
|
||||
raise errors.NotFound(reason=_('DNS zone %(zone)s not found' % dict(zone=domain)))
|
||||
raise errors.NotFound(
|
||||
reason=_('DNS zone %(zone)s not found') % dict(zone=domain)
|
||||
)
|
||||
# Get all forward resources for this host
|
||||
records = api.Command['dnsrecord_find'](domain, idnsname=parts[0])['result']
|
||||
for record in records:
|
||||
@ -602,7 +610,7 @@ class host_find(LDAPSearch):
|
||||
|
||||
has_output_params = LDAPSearch.has_output_params + host_output_params
|
||||
msg_summary = ngettext(
|
||||
'%(count)d host matched', '%(count)d hosts matched'
|
||||
'%(count)d host matched', '%(count)d hosts matched', 0
|
||||
)
|
||||
member_attributes = ['memberof', 'enrolledby', 'managedby']
|
||||
|
||||
|
@ -126,7 +126,7 @@ class hostgroup_find(LDAPSearch):
|
||||
"""
|
||||
member_attributes = ['member', 'memberof']
|
||||
msg_summary = ngettext(
|
||||
'%(count)d hostgroup matched', '%(count)d hostgroups matched'
|
||||
'%(count)d hostgroup matched', '%(count)d hostgroups matched', 0
|
||||
)
|
||||
|
||||
api.register(hostgroup_find)
|
||||
|
@ -379,11 +379,7 @@ class i18n_messages(Command):
|
||||
"validation_error":_("Text does not match field pattern"),
|
||||
},
|
||||
"ajax":{
|
||||
"401":_("Your kerberos ticket is no longer valid. "+
|
||||
"Please run kinit and then click 'Retry'. "+
|
||||
"If this is your first time running the IPA Web UI "+
|
||||
"<a href='/ipa/config/unauthorized.html'>"+
|
||||
"follow these directions</a> to configure your browser.")
|
||||
"401":_("Your kerberos ticket is no longer valid. Please run kinit and then click 'Retry'. If this is your first time running the IPA Web UI <a href='/ipa/config/unauthorized.html'>follow these directions</a> to configure your browser.")
|
||||
},
|
||||
"dirty":_("This page has unsaved changes. Please save or revert."),
|
||||
}
|
||||
|
@ -413,7 +413,9 @@ can use their Kerberos accounts.''')
|
||||
)
|
||||
except errors.NotFound:
|
||||
if not options.get('continue',False):
|
||||
raise errors.NotFound(reason=_('Container for %(container)s not found' % {'container':ldap_obj_name}))
|
||||
raise errors.NotFound(
|
||||
reason=_('Container for %(container)s not found') % {'container': ldap_obj_name}
|
||||
)
|
||||
else:
|
||||
truncated = False
|
||||
entries = []
|
||||
|
@ -106,7 +106,7 @@ class plugins(LocalOrRemote):
|
||||
"""Show all loaded plugins"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d plugin loaded', '%(count)d plugins loaded'
|
||||
'%(count)d plugin loaded', '%(count)d plugins loaded', 0
|
||||
)
|
||||
|
||||
takes_options = LocalOrRemote.takes_options + (
|
||||
|
@ -183,7 +183,7 @@ class netgroup_find(LDAPSearch):
|
||||
member_attributes = ['member', 'memberuser', 'memberhost', 'memberof']
|
||||
has_output_params = LDAPSearch.has_output_params + output_params
|
||||
msg_summary = ngettext(
|
||||
'%(count)d netgroup matched', '%(count)d netgroups matched'
|
||||
'%(count)d netgroup matched', '%(count)d netgroups matched', 0
|
||||
)
|
||||
|
||||
takes_options = LDAPSearch.takes_options + (
|
||||
|
@ -353,7 +353,7 @@ class permission_find(LDAPSearch):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d permission matched', '%(count)d permissions matched'
|
||||
'%(count)d permission matched', '%(count)d permissions matched', 0
|
||||
)
|
||||
has_output_params = LDAPSearch.has_output_params + output_params
|
||||
|
||||
|
@ -117,7 +117,7 @@ class privilege_find(LDAPSearch):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d privilege matched', '%(count)d privileges matched'
|
||||
'%(count)d privilege matched', '%(count)d privileges matched', 0
|
||||
)
|
||||
|
||||
api.register(privilege_find)
|
||||
|
@ -134,7 +134,7 @@ class role_find(LDAPSearch):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d role matched', '%(count)d roles matched'
|
||||
'%(count)d role matched', '%(count)d roles matched', 0
|
||||
)
|
||||
|
||||
api.register(role_find)
|
||||
|
@ -183,7 +183,7 @@ class selfservice_find(crud.Search):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d selfservice matched', '%(count)d selfservices matched'
|
||||
'%(count)d selfservice matched', '%(count)d selfservices matched', 0
|
||||
)
|
||||
|
||||
def execute(self, term, **kw):
|
||||
|
@ -432,7 +432,7 @@ class service_find(LDAPSearch):
|
||||
Search for IPA services.
|
||||
"""
|
||||
msg_summary = ngettext(
|
||||
'%(count)d service matched', '%(count)d services matched'
|
||||
'%(count)d service matched', '%(count)d services matched', 0
|
||||
)
|
||||
member_attributes = ['managedby']
|
||||
takes_options = LDAPSearch.takes_options
|
||||
|
@ -127,7 +127,7 @@ class sudocmd_find(LDAPSearch):
|
||||
"""
|
||||
|
||||
msg_summary = ngettext(
|
||||
'%(count)d sudo command matched', '%(count)d sudo command matched'
|
||||
'%(count)d sudo command matched', '%(count)d sudo command matched', 0
|
||||
)
|
||||
|
||||
api.register(sudocmd_find)
|
||||
|
@ -271,10 +271,9 @@ class user_add(LDAPCreate):
|
||||
if 'ipamaxusernamelength' in config:
|
||||
if len(keys[-1]) > int(config.get('ipamaxusernamelength')[0]):
|
||||
raise errors.ValidationError(
|
||||
name=self.obj.primary_key.cli_name, error=_(
|
||||
'can be at most %(len)d characters' % dict(
|
||||
len = int(config.get('ipamaxusernamelength')[0])
|
||||
)
|
||||
name=self.obj.primary_key.cli_name,
|
||||
error=_('can be at most %(len)d characters') % dict(
|
||||
len = int(config.get('ipamaxusernamelength')[0])
|
||||
)
|
||||
)
|
||||
entry_attrs.setdefault('loginshell', config.get('ipadefaultloginshell'))
|
||||
|
@ -488,10 +488,11 @@ class NGettextFactory(GettextFactory):
|
||||
*domain* (likely needed for 3rd-party plugins).
|
||||
"""
|
||||
|
||||
def __call__(self, singular, plural, count=0):
|
||||
def __call__(self, singular, plural, count):
|
||||
return NGettext(singular, plural, self.domain, self.localedir)
|
||||
|
||||
|
||||
# Process wide factories:
|
||||
_ = GettextFactory()
|
||||
ngettext = NGettextFactory()
|
||||
ugettext = _
|
||||
|
Loading…
Reference in New Issue
Block a user