[Checkins] SVN: zope.app.container/branches/3.5/ - fixed #221025 :
adding menu is sorted with translated item
Christophe Combelles
ccomb at free.fr
Mon Jun 16 04:59:45 EDT 2008
Log message for revision 87422:
- fixed #221025 : adding menu is sorted with translated item
by using a collator (better localized sorting)
Changed:
U zope.app.container/branches/3.5/CHANGES.txt
U zope.app.container/branches/3.5/setup.py
U zope.app.container/branches/3.5/src/zope/app/container/browser/adding.py
U zope.app.container/branches/3.5/src/zope/app/container/browser/commontasks.pt
U zope.app.container/branches/3.5/src/zope/app/container/browser/tests/test_adding.py
-=-
Modified: zope.app.container/branches/3.5/CHANGES.txt
===================================================================
--- zope.app.container/branches/3.5/CHANGES.txt 2008-06-16 08:48:28 UTC (rev 87421)
+++ zope.app.container/branches/3.5/CHANGES.txt 2008-06-16 08:59:45 UTC (rev 87422)
@@ -6,6 +6,8 @@
---------------------
- fixed #238579 / #163149: error with unicode traversing
+- fixed #221025 : adding menu is sorted with translated item
+ by using a collator (better localized sorting)
3.5.3 (2007-11-09)
------------------
Modified: zope.app.container/branches/3.5/setup.py
===================================================================
--- zope.app.container/branches/3.5/setup.py 2008-06-16 08:48:28 UTC (rev 87421)
+++ zope.app.container/branches/3.5/setup.py 2008-06-16 08:59:45 UTC (rev 87422)
@@ -85,6 +85,7 @@
'zope.app.broken',
'zope.copypastemove',
'ZODB3',
+ 'zope.i18n',
],
include_package_data = True,
zip_safe = False,
Modified: zope.app.container/branches/3.5/src/zope/app/container/browser/adding.py
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/browser/adding.py 2008-06-16 08:48:28 UTC (rev 87421)
+++ zope.app.container/branches/3.5/src/zope/app/container/browser/adding.py 2008-06-16 08:59:45 UTC (rev 87422)
@@ -22,6 +22,7 @@
__docformat__ = 'restructuredtext'
import zope.security.checker
+from zope.component import queryAdapter
from zope.component.interfaces import IFactory
from zope.event import notify
from zope.interface import implements
@@ -40,8 +41,9 @@
from zope.app.container.i18n import ZopeMessageFactory as _
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.publisher.browser.menu import getMenu
+from zope.i18n.interfaces.locales import ICollator
+from zope.i18n.locales.fallbackcollator import FallbackCollator
-
class Adding(BrowserView):
implements(IAdding, IPublishTraverse)
@@ -179,9 +181,16 @@
continue
elif item['extra']['factory'] != item['action']:
item['has_custom_add_view']=True
+ # translate here to have a localized sorting
+ item['title'] = zope.i18n.translate(item['title'],
+ context=self.request)
result.append(item)
- result.sort(lambda a, b: cmp(a['title'], b['title']))
+ # sort the adding info with a collator instead of a basic unicode sort
+ collator = queryAdapter(self.request.locale, ICollator)
+ if collator is None:
+ collator = FallbackCollator(self.request.locale)
+ result.sort(key = lambda x: collator.key(x['title']))
return result
def isSingleMenuItem(self):
Modified: zope.app.container/branches/3.5/src/zope/app/container/browser/commontasks.pt
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/browser/commontasks.pt 2008-06-16 08:48:28 UTC (rev 87421)
+++ zope.app.container/branches/3.5/src/zope/app/container/browser/commontasks.pt 2008-06-16 08:59:45 UTC (rev 87422)
@@ -1,5 +1,5 @@
<tal:block define="addingInfo context/@@+/addingInfo|nothing"
- condition="addingInfo" i18n:domain="zope">
+ condition="addingInfo">
<tal:block repeat="info addingInfo"
define="namesRequired context/@@+/nameAllowed">
@@ -15,7 +15,7 @@
tal:attributes="
href string:${baseurl}/@@contents.html?type_name=${info/action};
class info/selected"
- tal:content="info/title" i18n:translate="">Folder
+ tal:content="info/title">Folder
</a>
<a href="#"
@@ -25,7 +25,7 @@
tal:attributes="
href string:${baseurl}/@@+/action.html?type_name=${info/action};
class info/selected"
- tal:content="info/title" i18n:translate="">Folder
+ tal:content="info/title">Folder
</a>
<a href="#"
@@ -34,7 +34,7 @@
tal:attributes="
href python: info['action'][3:];
class info/selected"
- tal:content="info/title" i18n:translate="">Folder
+ tal:content="info/title">Folder
</a>
</div>
</tal:block>
Modified: zope.app.container/branches/3.5/src/zope/app/container/browser/tests/test_adding.py
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/browser/tests/test_adding.py 2008-06-16 08:48:28 UTC (rev 87421)
+++ zope.app.container/branches/3.5/src/zope/app/container/browser/tests/test_adding.py 2008-06-16 08:59:45 UTC (rev 87422)
@@ -224,7 +224,7 @@
... 'TestMenu')
>>> defineMenuItem(TestMenu, IAdding, '', 'item1')
- >>> defineMenuItem(TestMenu, IAdding, '', 'item2')
+ >>> defineMenuItem(TestMenu, IAdding, '', 'Item2')
>>> defineMenuItem(AddMenu, IAdding, '', 'item3', extra={'factory': 'f1'})
>>> defineMenuItem(AddMenu, IAdding, '', 'item4', extra={'factory': 'f2'})
@@ -263,18 +263,18 @@
>>> len(items)
1
>>> items[0]['title']
- 'item3'
+ u'item3'
>>> adding.menu_id = 'TestMenu'
>>> items = adding.addingInfo()
>>> len(items)
3
>>> items[0]['title']
- 'item1'
- >>> items[1]['title']
- 'item2'
+ u'item1'
+ >>> items[1]['title'] # the collator ordered this one correctly!
+ u'Item2'
>>> items[2]['title']
- 'item3'
+ u'item3'
"""
def test_constraint_driven_add():
More information about the Checkins
mailing list