← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/recife-gettranslationrows into lp:~launchpad/launchpad/recife.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers): code


= 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
-- 
https://code.launchpad.net/~jtv/launchpad/recife-gettranslationrows/+merge/41925
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/recife-gettranslationrows into lp:~launchpad/launchpad/recife.
=== modified file 'lib/lp/translations/model/pofile.py'
--- lib/lp/translations/model/pofile.py	2010-11-25 06:08:09 +0000
+++ lib/lp/translations/model/pofile.py	2010-11-26 05:38:59 +0000
@@ -1138,7 +1138,6 @@
                  "TranslationMessage.potemplate = %s)" % template_id,
             ]
 
-
         if ignore_obsolete:
             conditions.append("TranslationTemplateItem.sequence <> 0")
 
@@ -1159,10 +1158,11 @@
         # they must either be in the current template (sequence != 0, so not
         # "obsolete") or be in the current imported version of the translation
         # (is_current_upstream), or both.
-        return self._selectRows(
-            ignore_obsolete=False,
-            where="TranslationTemplateItem.sequence <> 0 OR "
-                "is_current_upstream IS TRUE")
+        traits = getUtility(ITranslationSideTraitsSet).getForTemplate(
+            self.potemplate)
+        flag = traits.flag_name
+        where = "TranslationTemplateItem.sequence <> 0 OR %s IS TRUE" % flag
+        return self._selectRows(ignore_obsolete=False, where=where)
 
     def getChangedRows(self):
         """See `IVPOExportSet`."""
@@ -1634,8 +1634,6 @@
         diverged_messages = set()
         for row in rows:
             assert row.pofile == pofile, 'Got a row for a different IPOFile.'
-            assert row.sequence != 0 or row.is_current_upstream, (
-                "Got uninteresting row.")
 
             msg_key = (row.msgid_singular, row.msgid_plural, row.context)
             if row.diverged is not None:

=== modified file 'lib/lp/translations/tests/test_pofile.py'
--- lib/lp/translations/tests/test_pofile.py	2010-11-25 22:26:25 +0000
+++ lib/lp/translations/tests/test_pofile.py	2010-11-26 05:38:59 +0000
@@ -1923,6 +1923,47 @@
                 "getTranslationRows does not sort obsolete messages "
                 "(sequence=0) to the end of the file.")
 
+    def test_getTranslationRows_obsolete_upstream(self):
+        # getTranslationRows includes translations marked as current
+        # that are for obsolete messages.
+        potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)
+        text = self.factory.getUniqueString()
+        translation = self.factory.makeCurrentTranslationMessage(
+            pofile=self.pofile, potmsgset=potmsgset, translations=[text])
+
+        rows = list(self.pofile.getTranslationRows())
+        self.assertEqual(1, len(rows))
+        vpoexport = rows[0]
+        self.assertEqual(self.pofile, vpoexport.pofile)
+        self.assertEqual(potmsgset, vpoexport.potmsgset)
+        self.assertEqual(text, vpoexport.translation0)
+
+        # The message is included, but is still marked as obsolete.
+        self.assertEqual(0, vpoexport.sequence)
+
+    def test_getTranslationRows_obsolete_ubuntu(self):
+        # getTranslationRows handles obsolete messages for Ubuntu
+        # POFiles just like it does for upstream POFiles.
+        package = self.factory.makeSourcePackage()
+        self.potemplate = self.factory.makePOTemplate(
+            distroseries=package.distroseries,
+            sourcepackagename=package.sourcepackagename)
+        self.pofile = self.factory.makePOFile(potemplate=self.potemplate)
+        potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)
+        text = self.factory.getUniqueString()
+        translation = self.factory.makeCurrentTranslationMessage(
+            pofile=self.pofile, potmsgset=potmsgset, translations=[text])
+
+        rows = list(self.pofile.getTranslationRows())
+        self.assertEqual(1, len(rows))
+        vpoexport = rows[0]
+        self.assertEqual(self.pofile, vpoexport.pofile)
+        self.assertEqual(potmsgset, vpoexport.potmsgset)
+        self.assertEqual(text, vpoexport.translation0)
+
+        # The message is included, but is still marked as obsolete.
+        self.assertEqual(0, vpoexport.sequence)
+
     def test_markChanged_sets_date(self):
         timestamp = datetime.now(pytz.UTC) - timedelta(days=14)
         self.pofile.markChanged(timestamp=timestamp)


Follow ups