Merge lp:~jtv/launchpad/recife-gettranslationrows into lp:~launchpad/launchpad/recife

Proposed by Jeroen T. Vermeulen on 2010-11-26
Status: Merged
Merged at revision: 9216
Proposed branch: lp:~jtv/launchpad/recife-gettranslationrows
Merge into: lp:~launchpad/launchpad/recife
Diff against target: 88 lines (+46/-7)
2 files modified
lib/lp/translations/model/pofile.py (+5/-7)
lib/lp/translations/tests/test_pofile.py (+41/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/recife-gettranslationrows
Reviewer Review Type Date Requested Status
Henning Eggers (community) code 2010-11-26 Approve on 2010-11-26
Steve Kowalik (community) code* Approve on 2010-11-26
Review via email: mp+41925@code.launchpad.net

Commit Message

Export obsolete messages side-awarely.

Description of the Change

= POFile.getTranslationRows =

This is a small fix for translations exports, to go into the Recife feature branch that we're about ready to land on db-devel.

It fixes a very small reliance on the pre-Recife data model: when exporting a translation, obsolete messages were taken from the upstream side (corresponding to "published imports" in the old model). That should be side-sensitive now: it makes more sense to import obsolete messages in the translation that is being exported.

Of the two tests I added, only one fails in the old model: the one with translations for the Ubuntu side. But until we're confident that all hard-coded sides are gone, it makes sense to test for both.

Jeroen

To post a comment you must log in.
Steve Kowalik (stevenk) wrote :

Thanks to Jeroen's explanation that zero is a magic number, I'm happy with this branch.

review: Approve (code*)
Henning Eggers (henninge) wrote :

Thanks for spotting and fixing this.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/model/pofile.py'
2--- lib/lp/translations/model/pofile.py 2010-11-25 06:08:09 +0000
3+++ lib/lp/translations/model/pofile.py 2010-11-26 05:38:59 +0000
4@@ -1138,7 +1138,6 @@
5 "TranslationMessage.potemplate = %s)" % template_id,
6 ]
7
8-
9 if ignore_obsolete:
10 conditions.append("TranslationTemplateItem.sequence <> 0")
11
12@@ -1159,10 +1158,11 @@
13 # they must either be in the current template (sequence != 0, so not
14 # "obsolete") or be in the current imported version of the translation
15 # (is_current_upstream), or both.
16- return self._selectRows(
17- ignore_obsolete=False,
18- where="TranslationTemplateItem.sequence <> 0 OR "
19- "is_current_upstream IS TRUE")
20+ traits = getUtility(ITranslationSideTraitsSet).getForTemplate(
21+ self.potemplate)
22+ flag = traits.flag_name
23+ where = "TranslationTemplateItem.sequence <> 0 OR %s IS TRUE" % flag
24+ return self._selectRows(ignore_obsolete=False, where=where)
25
26 def getChangedRows(self):
27 """See `IVPOExportSet`."""
28@@ -1634,8 +1634,6 @@
29 diverged_messages = set()
30 for row in rows:
31 assert row.pofile == pofile, 'Got a row for a different IPOFile.'
32- assert row.sequence != 0 or row.is_current_upstream, (
33- "Got uninteresting row.")
34
35 msg_key = (row.msgid_singular, row.msgid_plural, row.context)
36 if row.diverged is not None:
37
38=== modified file 'lib/lp/translations/tests/test_pofile.py'
39--- lib/lp/translations/tests/test_pofile.py 2010-11-25 22:26:25 +0000
40+++ lib/lp/translations/tests/test_pofile.py 2010-11-26 05:38:59 +0000
41@@ -1923,6 +1923,47 @@
42 "getTranslationRows does not sort obsolete messages "
43 "(sequence=0) to the end of the file.")
44
45+ def test_getTranslationRows_obsolete_upstream(self):
46+ # getTranslationRows includes translations marked as current
47+ # that are for obsolete messages.
48+ potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)
49+ text = self.factory.getUniqueString()
50+ translation = self.factory.makeCurrentTranslationMessage(
51+ pofile=self.pofile, potmsgset=potmsgset, translations=[text])
52+
53+ rows = list(self.pofile.getTranslationRows())
54+ self.assertEqual(1, len(rows))
55+ vpoexport = rows[0]
56+ self.assertEqual(self.pofile, vpoexport.pofile)
57+ self.assertEqual(potmsgset, vpoexport.potmsgset)
58+ self.assertEqual(text, vpoexport.translation0)
59+
60+ # The message is included, but is still marked as obsolete.
61+ self.assertEqual(0, vpoexport.sequence)
62+
63+ def test_getTranslationRows_obsolete_ubuntu(self):
64+ # getTranslationRows handles obsolete messages for Ubuntu
65+ # POFiles just like it does for upstream POFiles.
66+ package = self.factory.makeSourcePackage()
67+ self.potemplate = self.factory.makePOTemplate(
68+ distroseries=package.distroseries,
69+ sourcepackagename=package.sourcepackagename)
70+ self.pofile = self.factory.makePOFile(potemplate=self.potemplate)
71+ potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)
72+ text = self.factory.getUniqueString()
73+ translation = self.factory.makeCurrentTranslationMessage(
74+ pofile=self.pofile, potmsgset=potmsgset, translations=[text])
75+
76+ rows = list(self.pofile.getTranslationRows())
77+ self.assertEqual(1, len(rows))
78+ vpoexport = rows[0]
79+ self.assertEqual(self.pofile, vpoexport.pofile)
80+ self.assertEqual(potmsgset, vpoexport.potmsgset)
81+ self.assertEqual(text, vpoexport.translation0)
82+
83+ # The message is included, but is still marked as obsolete.
84+ self.assertEqual(0, vpoexport.sequence)
85+
86 def test_markChanged_sets_date(self):
87 timestamp = datetime.now(pytz.UTC) - timedelta(days=14)
88 self.pofile.markChanged(timestamp=timestamp)

Subscribers

People subscribed via source and target branches