Clean up i18n strings

This patch switches to named ("%(name)s") instead of positional ("%s")
substitutions for internationalized strings, so translators can
reorder the words.
This fixes https://fedorahosted.org/freeipa/ticket/2179 (xgettext no
longer gives warnings).

Also, some i18n calls are rewritten to translate the template before
substitutions, not after.
This commit is contained in:
Petr Viktorin
2012-02-10 04:27:53 -05:00
committed by Martin Kosek
parent eba3a341e6
commit 90d99f6017
5 changed files with 21 additions and 19 deletions

View File

@@ -185,7 +185,7 @@ class automember(LDAPObject):
try:
(gdn, entry_attrs) = ldap.get_entry(dn, [])
except errors.NotFound:
raise errors.NotFound(reason=_(u'Group: %s not found!' % groupname))
raise errors.NotFound(reason=_(u'Group: %s not found!') % groupname)
return gdn
def get_dn(self, *keys, **options):
@@ -212,7 +212,7 @@ class automember(LDAPObject):
if obj is not None:
return obj
else:
raise errors.NotFound(reason=_('%s is not a valid attribute.' % attr))
raise errors.NotFound(reason=_('%s is not a valid attribute.') % attr)
api.register(automember)
@@ -283,7 +283,7 @@ class automember_add_condition(LDAPUpdate):
try:
(tdn, test_attrs) = ldap.get_entry(dn, [])
except errors.NotFound:
raise errors.NotFound(reason=_(u'Auto member rule: %s not found!' % keys[0]))
raise errors.NotFound(reason=_(u'Auto member rule: %s not found!') % keys[0])
# Define container key
key = options['key']
# Check to see if the attribute is valid
@@ -369,7 +369,7 @@ class automember_remove_condition(LDAPUpdate):
try:
(tdn, test_attrs) = ldap.get_entry(dn, [])
except errors.NotFound:
raise errors.NotFound(reason=_(u'Auto member rule: %s not found!' % keys[0]))
raise errors.NotFound(reason=_(u'Auto member rule: %s not found!') % keys[0])
# Define container key
type_attr_default = {'group': 'manager', 'hostgroup': 'fqdn'}

View File

@@ -1644,8 +1644,8 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
Retrieve all LDAP entries matching the given criteria.
"""
member_attributes = []
member_param_incl_doc = _('Search for %s with these %s %s.')
member_param_excl_doc = _('Search for %s without these %s %s.')
member_param_incl_doc = _('Search for %(searched_object)s with these %(relationship)s %(ldap_object)s.')
member_param_excl_doc = _('Search for %(searched_object)s without these %(relationship)s %(ldap_object)s.')
# pointer to function for entries sorting
# if no function is assigned the entries are sorted by their primary key value
@@ -1684,18 +1684,20 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
relationship = self.obj.relationships.get(
attr, ['member', '', 'no_']
)
doc = self.member_param_incl_doc % (
self.obj.object_name_plural, relationship[0].lower(),
ldap_obj.object_name_plural
doc = self.member_param_incl_doc % dict(
searched_object=self.obj.object_name_plural,
relationship=relationship[0].lower(),
ldap_object=ldap_obj.object_name_plural
)
name = '%s%s' % (relationship[1], to_cli(ldap_obj_name))
yield Str(
'%s*' % name, cli_name='%ss' % name, doc=doc,
label=ldap_obj.object_name, csv=True
)
doc = self.member_param_excl_doc % (
self.obj.object_name_plural, relationship[0].lower(),
ldap_obj.object_name_plural
doc = self.member_param_excl_doc % dict(
searched_object=self.obj.object_name_plural,
relationship=relationship[0].lower(),
ldap_object=ldap_obj.object_name_plural
)
name = '%s%s' % (relationship[2], to_cli(ldap_obj_name))
yield Str(

View File

@@ -241,8 +241,8 @@ class config_mod(LDAPUpdate):
continue
if obj_attr not in new_allowed_attrs:
raise errors.ValidationError(name=attr,
error=_('%s default attribute %s would not be allowed!') \
% (obj, obj_attr))
error=_('%(obj)s default attribute %(attr)s would not be allowed!') \
% dict(obj=obj, attr=obj_attr))
if 'ipaselinuxusermapdefault' in options and options['ipaselinuxusermapdefault'] is None:
raise errors.ValidationError(name='ipaselinuxusermapdefault',

View File

@@ -587,8 +587,8 @@ class sudorule_add_option(LDAPQuery):
return dict(result=entry_attrs)
def output_for_cli(self, textui, result, cn, **options):
textui.print_dashed(_('Added option "%s" to Sudo Rule "%s"') % \
(options['ipasudoopt'], cn))
textui.print_dashed(_('Added option "%(option)s" to Sudo Rule "%(rule)s"') % \
dict(option=options['ipasudoopt'], rule=cn))
super(sudorule_add_option, self).output_for_cli(textui, result, cn, options)
@@ -642,8 +642,8 @@ class sudorule_remove_option(LDAPQuery):
return dict(result=entry_attrs)
def output_for_cli(self, textui, result, cn, **options):
textui.print_dashed(_('Removed option "%s" from Sudo Rule "%s"') % \
(options['ipasudoopt'], cn))
textui.print_dashed(_('Removed option "%(option)s" from Sudo Rule "%(rule)s"') % \
dict(option=options['ipasudoopt'], rule=cn))
super(sudorule_remove_option, self).output_for_cli(textui, result, cn, options)
api.register(sudorule_remove_option)