Merge lp:~salgado/launchpad/bug-433991 into lp:launchpad

Proposed by Guilherme Salgado on 2009-09-21
Status: Merged
Approved by: Brad Crittenden on 2009-09-21
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/bug-433991
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~salgado/launchpad/bug-433991
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical 2009-09-21 Approve on 2009-09-21
Henning Eggers (community) code 2009-09-21 Approve on 2009-09-21
Review via email: mp+12170@code.launchpad.net
To post a comment you must log in.
Guilherme Salgado (salgado) wrote :

= Summary =

Make sure zope.i18nmessageid.message.Message get interpolated when
building a page's title.

== Proposed fix ==

The new fmt:pagetitle formatter iterates over the breadcrumbs and join
their text in a single string, but the leaf breadcrumb may have Message
objects (from the view's .page_title) as their text, so when they're
joined they are not interpolated and we end up with things like 'Ask a
question about ${context}' in the title.

== Tests ==

./bin/test -vvm canonical.launchpad -t test_breadcrumbs

== Demo and Q/A ==

https://answers.launchpad.dev/ubuntu/+source/mozilla-firefox/+addquestion

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py
  lib/canonical/launchpad/browser/launchpad.py

Henning Eggers (henninge) wrote :

All fine as discussed on IRC. ;)

Henning

review: Approve (code)
Brad Crittenden (bac) :
review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/browser/launchpad.py'
2--- lib/canonical/launchpad/browser/launchpad.py 2009-09-20 19:40:47 +0000
3+++ lib/canonical/launchpad/browser/launchpad.py 2009-09-21 16:21:50 +0000
4@@ -36,10 +36,12 @@
5 import urllib
6 from datetime import timedelta, datetime
7
8+from zope import i18n
9 from zope.app import zapi
10 from zope.datetime import parseDatetimetz, tzinfo, DateTimeError
11 from zope.component import getUtility, queryAdapter
12 from zope.interface import implements
13+from zope.i18nmessageid import Message
14 from zope.publisher.interfaces import NotFound
15 from zope.publisher.interfaces.browser import IBrowserPublisher
16 from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
17@@ -284,6 +286,8 @@
18 template_api = PageTemplateContextsAPI(
19 dict(context=obj, template=template, view=view))
20 title = template_api.pagetitle()
21+ if isinstance(title, Message):
22+ title = i18n.translate(title, context=self.request)
23 breadcrumb = Breadcrumb(None)
24 breadcrumb._url = url
25 breadcrumb.text = title
26
27=== modified file 'lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py'
28--- lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py 2009-09-18 12:15:42 +0000
29+++ lib/canonical/launchpad/webapp/tests/test_breadcrumbs.py 2009-09-21 16:21:50 +0000
30@@ -6,10 +6,13 @@
31 import unittest
32
33 from zope.interface import implements
34+from zope.i18nmessageid import Message
35
36+from canonical.launchpad.browser.launchpad import Hierarchy
37 from canonical.launchpad.webapp.breadcrumb import Breadcrumb
38 from canonical.launchpad.webapp.interfaces import ICanonicalUrlData
39 from canonical.launchpad.webapp.publisher import canonical_url
40+from canonical.launchpad.webapp.servers import LaunchpadTestRequest
41 from canonical.launchpad.webapp.tests.breadcrumbs import (
42 BaseBreadcrumbTestCase)
43 from lp.testing import login, TestCase
44@@ -63,6 +66,22 @@
45 self.assertEquals(texts[-1],
46 '%s project files' % self.product.displayname)
47
48+ def test_zope_i18n_Messages_are_interpolated(self):
49+ # Views can use zope.i18nmessageid.Message as their title when they
50+ # want to i18n it, but when that's the case we need to
51+ # translate/interpolate the string.
52+ class TestView:
53+ """A test view that uses a Message as its page_title."""
54+ page_title = Message(
55+ '${name} test', mapping={'name': 'breadcrumb'})
56+ __name__ = 'test-page'
57+ test_view = TestView()
58+ request = LaunchpadTestRequest()
59+ request.traversed_objects = [self.product, test_view]
60+ hierarchy_view = Hierarchy(self.product, request)
61+ breadcrumb = hierarchy_view.makeBreadcrumbForRequestedPage()
62+ self.assertEquals(breadcrumb.text, 'breadcrumb test')
63+
64
65 class TestExtraVHostBreadcrumbsOnHierarchyView(BaseBreadcrumbTestCase):
66 """How our breadcrumbs behave when using a vhost other than the main one?
67