[Checkins] SVN: zope.app.container/trunk/s Fix #221025 : adding
menu is sorted with translated items
Jacob Holm
jh at improva.dk
Fri Jun 13 11:35:01 EDT 2008
Good idea, but might I suggest using the collation support in zope.i18n
to help with the actual sorting?
Something like changing
result.sort(lambda a, b: cmp(a['title'], b['title']))
into:
try:
collator = zope.i18n.interfaces.ICollator(self.request.locale)
except ComponenLookupError:
collator =
zope.i18n.locales.fallbackcollator.FallbackCollator(self.request.locale)
result.sort(key = lambda x: collator.key(x['title']))
(If the fallbackcollator had been registered by default in zope.i18n
this would have been easier, but unfortunately it is not...)
Regards
- Jacob
Christopher Combelles wrote:
> Log message for revision 87365:
> Fix #221025 : adding menu is sorted with translated items
>
>
> Changed:
> U zope.app.container/trunk/setup.py
> U zope.app.container/trunk/src/zope/app/container/browser/adding.py
> U zope.app.container/trunk/src/zope/app/container/browser/commontasks.pt
> U zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py
>
> -=-
> Modified: zope.app.container/trunk/setup.py
> ===================================================================
> --- zope.app.container/trunk/setup.py 2008-06-13 13:48:19 UTC (rev 87364)
> +++ zope.app.container/trunk/setup.py 2008-06-13 13:53:01 UTC (rev 87365)
> @@ -84,6 +84,7 @@
> 'zope.app.broken',
> 'zope.copypastemove',
> 'ZODB3',
> + 'zope.i18n',
> ],
> include_package_data = True,
> zip_safe = False,
>
> Modified: zope.app.container/trunk/src/zope/app/container/browser/adding.py
> ===================================================================
> --- zope.app.container/trunk/src/zope/app/container/browser/adding.py 2008-06-13 13:48:19 UTC (rev 87364)
> +++ zope.app.container/trunk/src/zope/app/container/browser/adding.py 2008-06-13 13:53:01 UTC (rev 87365)
> @@ -43,8 +43,8 @@
> from zope.app.container.interfaces import IContainerNamesContainer
> from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
> from zope.app.publisher.browser.menu import getMenu
> +from zope.i18n import translate
>
> -
> class Adding(BrowserView):
> implements(IAdding, IPublishTraverse)
>
> @@ -182,6 +182,9 @@
> 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']))
>
> Modified: zope.app.container/trunk/src/zope/app/container/browser/commontasks.pt
> ===================================================================
> --- zope.app.container/trunk/src/zope/app/container/browser/commontasks.pt 2008-06-13 13:48:19 UTC (rev 87364)
> +++ zope.app.container/trunk/src/zope/app/container/browser/commontasks.pt 2008-06-13 13:53:01 UTC (rev 87365)
> @@ -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/trunk/src/zope/app/container/browser/tests/test_adding.py
> ===================================================================
> --- zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py 2008-06-13 13:48:19 UTC (rev 87364)
> +++ zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py 2008-06-13 13:53:01 UTC (rev 87365)
> @@ -264,18 +264,18 @@
> >>> len(items)
> 1
> >>> items[0]['title']
> - 'item3'
> + u'item3'
>
> >>> adding.menu_id = 'TestMenu'
> >>> items = adding.addingInfo()
> >>> len(items)
> 3
> >>> items[0]['title']
> - 'item1'
> + u'item1'
> >>> items[1]['title']
> - 'item2'
> + u'item2'
> >>> items[2]['title']
> - 'item3'
> + u'item3'
> """
>
> def test_constraint_driven_add():
>
> _______________________________________________
> Checkins mailing list
> Checkins at zope.org
> http://mail.zope.org/mailman/listinfo/checkins
>
More information about the Checkins
mailing list