* Wrap each topic description in _()

* Replace the use of if 'topic' in dir(module) with the more
  Pythonic and efficient getattr(module, 'topic', None)

* Make sure to invoke unicode on the value returned from _()
  otherwise you'll get a GettextFactory instance, not a string

* Clean up trailing whitespace errors

--
John Dennis <jden...@redhat.com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
From 25aebdb8bcb2c05c037145e2eace1999a4dbd322 Mon Sep 17 00:00:00 2001
From: John Dennis <jden...@redhat.com>
Date: Wed, 24 Aug 2011 17:27:32 -0400
Subject: [PATCH 44/44] ticket 1705 - internationalize help topics
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

* Wrap each topic description in _()

* Replace the use of if 'topic' in dir(module) with the more
  Pythonic and efficient getattr(module, 'topic', None)

* Make sure to invoke unicode on the value returned from _()
  otherwise you'll get a GettextFactory instance, not a string

* Clean up trailing whitespace errors
---
 ipalib/cli.py                  |   10 ++++------
 ipalib/plugins/hbacrule.py     |    2 +-
 ipalib/plugins/hbacsvc.py      |    2 +-
 ipalib/plugins/hbacsvcgroup.py |    2 +-
 ipalib/plugins/sudocmd.py      |    2 +-
 ipalib/plugins/sudocmdgroup.py |    2 +-
 ipalib/plugins/sudorule.py     |    2 +-
 7 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/ipalib/cli.py b/ipalib/cli.py
index 5e1365d..5b55443 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -536,7 +536,7 @@ class textui(backend.Backend):
 
         If Default parameter is not None, user can enter an empty input instead
         of Yes/No answer. Value passed to Default is returned in that case.
-        
+
         If Default parameter is None, user is asked for Yes/No answer until
         a correct answer is provided. Answer is then returned.
 
@@ -672,10 +672,8 @@ class help(frontend.Local):
             __import__(module_name)
         module = sys.modules[module_name]
 
-        dir_list = dir(module)
-        if 'topic' in dir_list:
-            topic = module.topic
-        else:
+        topic = getattr(module, 'topic', None)
+        if topic is None:
             topic = (self._get_command_module(module_name), None)
 
         return topic
@@ -726,7 +724,7 @@ class help(frontend.Local):
                         mcl = max((self._topics[topic_name][2][mod_name][1], len(c.name)))
                         self._topics[topic_name][2][mod_name][1] = mcl
                     else:
-                        self._topics[topic_name] = [topic[1], 0, {mod_name: [doc, 0, [c]]}]
+                        self._topics[topic_name] = [unicode(_(topic[1])), 0, {mod_name: [doc, 0, [c]]}]
                         self._count_topic_mcl(topic_name, mod_name)
             else:
                 self._builtins.append(c)
diff --git a/ipalib/plugins/hbacrule.py b/ipalib/plugins/hbacrule.py
index 0d8474f..1ea0259 100644
--- a/ipalib/plugins/hbacrule.py
+++ b/ipalib/plugins/hbacrule.py
@@ -85,7 +85,7 @@ from ipalib import AccessTime, Password, Str, StrEnum
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
 
-topic = ('hbac', 'Host-based access control commands')
+topic = ('hbac', _('Host-based access control commands'))
 
 def validate_type(ugettext, type):
     if type.lower() == 'deny':
diff --git a/ipalib/plugins/hbacsvc.py b/ipalib/plugins/hbacsvc.py
index c2041c3..a45d9d6 100644
--- a/ipalib/plugins/hbacsvc.py
+++ b/ipalib/plugins/hbacsvc.py
@@ -45,7 +45,7 @@ from ipalib.plugins.baseldap import LDAPUpdate, LDAPSearch, LDAPRetrieve
 
 from ipalib import _, ngettext
 
-topic = ('hbac', 'Host based access control commands')
+topic = ('hbac', _('Host based access control commands'))
 
 class hbacsvc(LDAPObject):
     """
diff --git a/ipalib/plugins/hbacsvcgroup.py b/ipalib/plugins/hbacsvcgroup.py
index 12db5f3..5154b18 100644
--- a/ipalib/plugins/hbacsvcgroup.py
+++ b/ipalib/plugins/hbacsvcgroup.py
@@ -45,7 +45,7 @@ from ipalib import api, errors
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
 
-topic = ('hbac', 'Host based access control commands')
+topic = ('hbac', _('Host based access control commands'))
 
 class hbacsvcgroup(LDAPObject):
     """
diff --git a/ipalib/plugins/sudocmd.py b/ipalib/plugins/sudocmd.py
index da78f0e..af8ab03 100644
--- a/ipalib/plugins/sudocmd.py
+++ b/ipalib/plugins/sudocmd.py
@@ -40,7 +40,7 @@ from ipalib import Str
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
 
-topic = ('sudo', 'commands for controlling sudo configuration')
+topic = ('sudo', _('commands for controlling sudo configuration'))
 
 class sudocmd(LDAPObject):
     """
diff --git a/ipalib/plugins/sudocmdgroup.py b/ipalib/plugins/sudocmdgroup.py
index e613f46..60d4b38 100644
--- a/ipalib/plugins/sudocmdgroup.py
+++ b/ipalib/plugins/sudocmdgroup.py
@@ -44,7 +44,7 @@ from ipalib import Str
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
 
-topic = ('sudo', 'commands for controlling sudo configuration')
+topic = ('sudo', _('commands for controlling sudo configuration'))
 
 class sudocmdgroup(LDAPObject):
     """
diff --git a/ipalib/plugins/sudorule.py b/ipalib/plugins/sudorule.py
index 1785947..45ddca7 100644
--- a/ipalib/plugins/sudorule.py
+++ b/ipalib/plugins/sudorule.py
@@ -38,7 +38,7 @@ from ipalib import Str, StrEnum
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
 
-topic = ('sudo', 'Commands for controlling sudo configuration')
+topic = ('sudo', _('Commands for controlling sudo configuration'))
 
 def deprecated(attribute):
     raise errors.ValidationError(name=attribute, error=_('this option has been deprecated.'))
-- 
1.7.4.4

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

Reply via email to