On 02/14/2012 10:49 AM, Alexander Bokovoy wrote:
On Tue, 14 Feb 2012, Petr Viktorin wrote:

This patch wraps exception messages in _()

https://fedorahosted.org/freeipa/ticket/2267
ACK.

I was looking at hbactest and there are also some
non-internationalized messages returned. Maybe you could combine them
together with a slightly updated version of this patch?


Yes; attaching updated patch. I also wrapped some texts in ipalib.output in _() calls.


--
PetrĀ³
>From 57c65171d46ac6753029a91b139c0a3edfc77302 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 10 Feb 2012 05:27:24 -0500
Subject: [PATCH] Internationalization for HBAC and ipalib.output

* hbacrule: Internationalize HBAC rule "all" category exceptions
  https://fedorahosted.org/freeipa/ticket/2267

* hbactest: Use internationalized names (doc) instead of names
  for output items
  Also don't convert result to bool, `not` does it implicitly

* ipalib.output: Internationalize descriptions of some standard entries
---
 ipalib/output.py           |   12 ++++++------
 ipalib/plugins/hbacrule.py |    8 ++++----
 ipalib/plugins/hbactest.py |    6 +++---
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/ipalib/output.py b/ipalib/output.py
index 61713627437596eea1e203c08b08f10d2d636a47..1202ee19923bd6710a4c4e82a108d79ec63251b8 100644
--- a/ipalib/output.py
+++ b/ipalib/output.py
@@ -111,11 +111,11 @@ class ListOfEntries(Output):
 result = Output('result', doc=_('All commands should at least have a result'))
 
 summary = Output('summary', (unicode, NoneType),
-    'User-friendly description of action performed'
+    _('User-friendly description of action performed')
 )
 
 value = Output('value', unicode,
-    "The primary_key value of the entry, e.g. 'jdoe' for a user",
+    _("The primary_key value of the entry, e.g. 'jdoe' for a user"),
     flags=['no_display'],
 )
 
@@ -130,19 +130,19 @@ standard_entry = (
 standard_list_of_entries = (
     summary,
     ListOfEntries('result'),
-    Output('count', int, 'Number of entries returned'),
-    Output('truncated', bool, 'True if not all results were returned'),
+    Output('count', int, _('Number of entries returned')),
+    Output('truncated', bool, _('True if not all results were returned')),
 )
 
 standard_delete = (
     summary,
-    Output('result', dict, 'list of deletions that failed'),
+    Output('result', dict, _('List of deletions that failed')),
     value,
 )
 
 standard_boolean = (
     summary,
-    Output('result', bool, 'True means the operation was successful'),
+    Output('result', bool, _('True means the operation was successful')),
     value,
 )
 
diff --git a/ipalib/plugins/hbacrule.py b/ipalib/plugins/hbacrule.py
index c83305738b6b39ae109a3e738241ed7c0ce28a85..4666485569c365c9128f2dd04751a67cf71d47e1 100644
--- a/ipalib/plugins/hbacrule.py
+++ b/ipalib/plugins/hbacrule.py
@@ -265,13 +265,13 @@ class hbacrule_mod(LDAPUpdate):
             self.obj.handle_not_found(*keys)
 
         if is_all(options, 'usercategory') and 'memberuser' in entry_attrs:
-            raise errors.MutuallyExclusiveError(reason="user category cannot be set to 'all' while there are allowed users")
+            raise errors.MutuallyExclusiveError(reason=_("user category cannot be set to 'all' while there are allowed users"))
         if is_all(options, 'hostcategory') and 'memberhost' in entry_attrs:
-            raise errors.MutuallyExclusiveError(reason="host category cannot be set to 'all' while there are allowed hosts")
+            raise errors.MutuallyExclusiveError(reason=_("host category cannot be set to 'all' while there are allowed hosts"))
         if is_all(options, 'sourcehostcategory') and 'sourcehost' in entry_attrs:
-            raise errors.MutuallyExclusiveError(reason="sourcehost category cannot be set to 'all' while there are allowed source hosts")
+            raise errors.MutuallyExclusiveError(reason=_("sourcehost category cannot be set to 'all' while there are allowed sourcehosts"))
         if is_all(options, 'servicecategory') and 'memberservice' in entry_attrs:
-            raise errors.MutuallyExclusiveError(reason="service category cannot be set to 'all' while there are allowed services")
+            raise errors.MutuallyExclusiveError(reason=_("service category cannot be set to 'all' while there are allowed services"))
         return dn
 
 api.register(hbacrule_mod)
diff --git a/ipalib/plugins/hbactest.py b/ipalib/plugins/hbactest.py
index 92b7145a3fca717b4699749c2ec2b88ae3647cd5..b81dca3deb5a45bb092e3ae2adf3119ef256ff9e 100644
--- a/ipalib/plugins/hbactest.py
+++ b/ipalib/plugins/hbactest.py
@@ -359,7 +359,7 @@ class hbactest(Command):
                     if res == pyhbac.HBAC_EVAL_DENY:
                         notmatched_rules.append(ipa_rule.name)
                     if warning_flag:
-                        warning_rules.append(u'Sourcehost value of rule "%s" is ignored' % (ipa_rule.name))
+                        warning_rules.append(_(u'Sourcehost value of rule "%s" is ignored') % (ipa_rule.name))
                 except pyhbac.HbacError as (code, rule_name):
                     if code == pyhbac.HBAC_EVAL_ERROR:
                         error_rules.append(rule_name)
@@ -402,7 +402,7 @@ class hbactest(Command):
                 continue
             result = output[o]
             if isinstance(result, (list, tuple)):
-                    textui.print_attribute(outp.name, result, '%s: %s', 1, True)
+                textui.print_attribute(unicode(outp.doc), result, '%s: %s', 1, True)
             elif isinstance(result, (unicode, bool)):
                 if o == 'summary':
                     textui.print_summary(result)
@@ -410,6 +410,6 @@ class hbactest(Command):
                     textui.print_indented(result)
 
         # Propagate integer value for result. It will give proper command line result for scripts
-        return int(not bool(output['value']))
+        return int(not output['value'])
 
 api.register(hbactest)
-- 
1.7.7.6

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

Reply via email to