This fixes https://fedorahosted.org/freeipa/ticket/2179 (i18n strings do not use named substitutions), and changes some i18n calls to translate the template before substitutions, not after.


A i18n rule of thumb: only put a literal string in the _() call (unless special provisions are made).


--
PetrĀ³
>From de473d9eda10455fb174b8aa0ab0eccbe51e2fbc Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 10 Feb 2012 04:27:53 -0500
Subject: [PATCH] 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.
---
 ipalib/plugins/automember.py  |    8 ++++----
 ipalib/plugins/baseldap.py    |   18 ++++++++++--------
 ipalib/plugins/config.py      |    4 ++--
 ipalib/plugins/sudorule.py    |    8 ++++----
 ipaserver/plugins/selfsign.py |    2 +-
 5 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/ipalib/plugins/automember.py b/ipalib/plugins/automember.py
index 3b652185e1c1a69bea5b653f8ac4c3895415b31b..fabc9bb35a3803475ee1647aea264e29ea8a6f20 100644
--- a/ipalib/plugins/automember.py
+++ b/ipalib/plugins/automember.py
@@ -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'}
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 66ba4eff3064774f4e14e8cf737c80a13eb01eb4..66339ccad2473d81f267017746939d486f713e46 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -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(
diff --git a/ipalib/plugins/config.py b/ipalib/plugins/config.py
index 1455771d18e24868f46cb7e96240090e28658880..ecf424646674040cd9437697691b9dff4c3744bc 100644
--- a/ipalib/plugins/config.py
+++ b/ipalib/plugins/config.py
@@ -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',
diff --git a/ipalib/plugins/sudorule.py b/ipalib/plugins/sudorule.py
index 05fba455d43b152fb0b189bc745531b3bd427419..ff7b756a3b27c089b9718c72ed93f13dfa3fb44a 100644
--- a/ipalib/plugins/sudorule.py
+++ b/ipalib/plugins/sudorule.py
@@ -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)
diff --git a/ipaserver/plugins/selfsign.py b/ipaserver/plugins/selfsign.py
index 36850f139843d1b8e8acbb37937cc6e4c636112d..2f13b1fd583cba851f86ce0fe1897a09c2b1550f 100644
--- a/ipaserver/plugins/selfsign.py
+++ b/ipaserver/plugins/selfsign.py
@@ -101,7 +101,7 @@ class ra(rabase.rabase):
         except errors.CertificateOperationError, e:
             raise e
         except NSPRError, e:
-            raise errors.CertificateOperationError(error=_('unable to decode csr: %s' % e))
+            raise errors.CertificateOperationError(error=_('unable to decode csr: %s') % e)
 
         # certutil wants the CSR to have have a header and footer. Add one
         # if it isn't there.
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to