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