[Checkins] SVN: grok/branches/1.1/ Internationalization of title and description of roles are not lost anymore.

Vincent Fretin vincent.fretin at gmail.com
Fri Jul 23 04:50:58 EDT 2010


Log message for revision 114947:
  Internationalization of title and description of roles are not lost anymore.

Changed:
  U   grok/branches/1.1/CHANGES.txt
  U   grok/branches/1.1/setup.py
  U   grok/branches/1.1/src/grok/meta.py
  A   grok/branches/1.1/src/grok/tests/security/role_i18n.py

-=-
Modified: grok/branches/1.1/CHANGES.txt
===================================================================
--- grok/branches/1.1/CHANGES.txt	2010-07-23 05:24:08 UTC (rev 114946)
+++ grok/branches/1.1/CHANGES.txt	2010-07-23 08:50:57 UTC (rev 114947)
@@ -4,6 +4,8 @@
 1.1.2 (unreleased)
 ==================
 
+- Internationalization of title and description of roles are not lost anymore.
+
 - `create_application` now raises a `KeyError`, in cases of key
   duplication, to match the ``zope.container`` behavior. Tests have
   been adapted accordingly.

Modified: grok/branches/1.1/setup.py
===================================================================
--- grok/branches/1.1/setup.py	2010-07-23 05:24:08 UTC (rev 114946)
+++ grok/branches/1.1/setup.py	2010-07-23 08:50:57 UTC (rev 114947)
@@ -72,6 +72,7 @@
                       'zope.exceptions',
                       'zope.formlib',
                       'zope.i18n',
+                      'zope.i18nmessageid',
                       'zope.interface',
                       'zope.intid',
                       'zope.keyreference',

Modified: grok/branches/1.1/src/grok/meta.py
===================================================================
--- grok/branches/1.1/src/grok/meta.py	2010-07-23 05:24:08 UTC (rev 114946)
+++ grok/branches/1.1/src/grok/meta.py	2010-07-23 08:50:57 UTC (rev 114947)
@@ -34,6 +34,7 @@
 
 from zope.app.publisher.xmlrpc import MethodPublisher
 
+from zope.i18nmessageid import Message
 from zope.intid import IntIds
 from zope.intid.interfaces import IIntIds
 from zope.catalog.catalog import Catalog
@@ -267,7 +268,11 @@
                 "grok.name to specify one.", factory)
         # We can safely convert to unicode, since the directives makes sure
         # it is either unicode already or ASCII.
-        role = factory(unicode(name), unicode(title), unicode(description))
+        if not isinstance(title, Message):
+            title = unicode(title)
+        if not isinstance(description, Message):
+            description = unicode(description)
+        role = factory(unicode(name), title, description)
 
         config.action(
             discriminator=('utility', IRole, name),

Added: grok/branches/1.1/src/grok/tests/security/role_i18n.py
===================================================================
--- grok/branches/1.1/src/grok/tests/security/role_i18n.py	                        (rev 0)
+++ grok/branches/1.1/src/grok/tests/security/role_i18n.py	2010-07-23 08:50:57 UTC (rev 114947)
@@ -0,0 +1,75 @@
+"""
+A Role component have a title and description, that can be internationalized.
+
+Let's grok this package and check we still have a Message object for the
+internationalized title and description of the defined roles.
+
+  >>> grok.testing.grok(__name__)
+  >>> from zope.securitypolicy.interfaces import IRole
+  >>> from zope.component import getUtility
+  >>> from zope.i18nmessageid import Message
+
+A grok.Role without any internationalization.
+The id, title and description should be unicode::
+
+  >>> role = getUtility(IRole, name="RoleWithoutI18n")
+  >>> role.id
+  u'RoleWithoutI18n'
+  >>> role.title
+  u'RoleWithoutI18n'
+  >>> role.description
+  u'My role without i18n'
+  >>>
+  >>> isinstance(role.id, Message)
+  False
+  >>> isinstance(role.title, Message)
+  False
+  >>> isinstance(role.description, Message)
+  False
+
+A grok.Role registered with the name and description directives only, both
+internationalized.
+The id is taken from the name directive and should not be a Message object.
+The title is taken from the name directive because the title directive is not used.
+::
+
+  >>> role = getUtility(IRole, name="RoleWithI18n")
+  >>> isinstance(role.id, Message)
+  False
+  >>> isinstance(role.title, Message)
+  True
+  >>> isinstance(role.description, Message)
+  True
+
+A grok.Role registered with name, title and description directives::
+
+  >>> role = getUtility(IRole, name="RoleWithI18nTitle")
+  >>> isinstance(role.id, Message)
+  False
+  >>> isinstance(role.title, Message)
+  True
+  >>> isinstance(role.description, Message)
+  True
+"""
+
+import grok
+import zope.interface
+from zope.i18nmessageid import MessageFactory
+
+_ = MessageFactory("testi18n")
+
+
+class RoleWithoutI18n(grok.Role):
+    grok.name('RoleWithoutI18n')
+    grok.description('My role without i18n')
+
+
+class RoleWithI18n(grok.Role):
+    grok.name(_('RoleWithI18n'))
+    grok.description(_(u'My role with i18n'))
+
+
+class RoleWithI18nTitle(grok.Role):
+    grok.name('RoleWithI18nTitle')
+    grok.title(_('RoleWithI18n'))
+    grok.description(_(u'My role with i18n'))



More information about the checkins mailing list