Merge lp:~adeuring/launchpad/bug-702468 into lp:launchpad

Proposed by Abel Deuring
Status: Merged
Approved by: Abel Deuring
Approved revision: no longer in the source branch.
Merged at revision: 12387
Proposed branch: lp:~adeuring/launchpad/bug-702468
Merge into: lp:launchpad
Diff against target: 98 lines (+40/-6)
2 files modified
lib/lp/translations/model/potmsgset.py (+10/-0)
lib/lp/translations/tests/test_setcurrenttranslation.py (+30/-6)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-702468
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Abel Deuring (community) Needs Resubmitting
Curtis Hovey (community) code Approve
j.c.sackett (community) code* Approve
Review via email: mp+49205@code.launchpad.net

Commit message

[r=henninge,jcsackett,sinzui][bug=702468] If a yet untranslated upstream message is translated for the first time, and if upstream -> Ubuntu translation sharing is enabled, the new translation becomes current for Ubuntu too, even if there was already a current Ubuntu translation.

Description of the change

This branch fixes bug 702468: First upstream translation does not replace Ubuntu-only translation.

The flags TranslationMessage.is_current_(upstream|ubuntu) are set in
POTMsgSet._setTranslation().

The bug describes the situation that we have no incumbent message
and the "twin" message (i.e. the new message) is either shared
or diverged but not shared with the other side. The decision_matrix
entries for these cases are
decision_matrix['incumbent_none']['twin_shared'] and
decision_matrix['incumbent_none']['twin_diverged'], respectively.

The treatment of the translation on the "other side" for these cases
is described by the "decision character" '*', so this branch changes
the "elif character == '*':" part of the the method _setTranslation().

The "decision character" '*' is also used in
decision_matrix['incumbent_shared'], but the "elif incumbent_message
is None:" in my patch ensures that the method behaves as before in
this case.

The existing tests in test_setcurrenttranslation.py covered the
case "existing translation in Ubuntu, no translation in upstream"
already, so I only changed the expected data for the two "relevant"
tests.

test: ./bin/test -vvt lp.translations.tests.test_setcurrenttranslation

no lint

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

This looks good to land.

review: Approve (code*)
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thanks.

review: Approve (code)
Revision history for this message
Abel Deuring (adeuring) wrote :

Henning,

As discussed last week, I've disabled the flow "new current translation without a previous current translation becomes the current translation on the other side, if the other side already has a current translation" for the direction "new current Ubuntu translation overrides current upstream translation".

Looking through the existing tests, I think that they cover all situations, so I did not add any.

review: Needs Resubmitting
Revision history for this message
Henning Eggers (henninge) wrote :

Abel,
thank you for this update! It looks very well done to me. I have just one remaining request.

Please add a stub for selectUpstreamTranslation to SetCurrentTranslationTestMixin with a docstring and a "raise NotImplementedError". That makes it clearer where that is coming from. Also, you should either fix the parameter documentation in selectUpstreamTranslation ("tm" twice) or remove it completely (because it is pretty obvious ;).

Cheers,
Henning

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/model/potmsgset.py'
--- lib/lp/translations/model/potmsgset.py 2011-02-04 17:14:20 +0000
+++ lib/lp/translations/model/potmsgset.py 2011-02-15 11:46:10 +0000
@@ -1028,6 +1028,16 @@
1028 self, pofile.potemplate, pofile.language))1028 self, pofile.potemplate, pofile.language))
1029 if other_incumbent is None:1029 if other_incumbent is None:
1030 traits.other_side_traits.setFlag(message, True)1030 traits.other_side_traits.setFlag(message, True)
1031 elif (incumbent_message is None and
1032 traits.side == TranslationSide.UPSTREAM):
1033 # If this is the first upstream translation, we
1034 # we use it as the current Ubuntu translation
1035 # too, overriding a possibly existing current
1036 # Ubuntu translation.
1037 if other_incumbent is not None:
1038 traits.other_side_traits.setFlag(
1039 other_incumbent, False)
1040 traits.other_side_traits.setFlag(message, True)
1031 elif character == '+':1041 elif character == '+':
1032 if share_with_other_side:1042 if share_with_other_side:
1033 traits.other_side_traits.setFlag(incumbent_message, False)1043 traits.other_side_traits.setFlag(incumbent_message, False)
10341044
=== modified file 'lib/lp/translations/tests/test_setcurrenttranslation.py'
--- lib/lp/translations/tests/test_setcurrenttranslation.py 2010-11-18 04:08:16 +0000
+++ lib/lp/translations/tests/test_setcurrenttranslation.py 2011-02-15 11:46:10 +0000
@@ -161,6 +161,12 @@
161 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(161 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
162 tm, None, tm, [])162 tm, None, tm, [])
163163
164 def selectUpstreamTranslation(self, tm, tm_other):
165 # Return the upstream translation.
166 # :param tm: A translation for this side.
167 # :param tm_other: A translation for the other side.
168 raise NotImplementedError
169
164 def test_c_None__n_None__o_shared(self, follows=False):170 def test_c_None__n_None__o_shared(self, follows=False):
165 # Current translation is None, and we have found no171 # Current translation is None, and we have found no
166 # existing TM matching new translations.172 # existing TM matching new translations.
@@ -175,10 +181,17 @@
175 new_translations, share_with_other_side=follows)181 new_translations, share_with_other_side=follows)
176182
177 # We end up with a shared current translation.183 # We end up with a shared current translation.
178 # Current for other context one stays the same.184 # Current for other context one stays the same, if the
185 # other side does not follow this side.
179 self.assertTrue(tm is not None)186 self.assertTrue(tm is not None)
187 if follows:
188 # Even if the other side is supposed to follow this side,
189 # we ovverride the other only if the current side is Ubuntu.
190 expected_other = self.selectUpstreamTranslation(tm, tm_other)
191 else:
192 expected_other = tm_other
180 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(193 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
181 tm, None, tm_other, [])194 tm, None, expected_other, [])
182195
183 def test_c_None__n_None__o_shared__follows(self):196 def test_c_None__n_None__o_shared__follows(self):
184 # There is no current translation, though there is a shared one197 # There is no current translation, though there is a shared one
@@ -318,14 +331,17 @@
318 new_translations, share_with_other_side=True)331 new_translations, share_with_other_side=True)
319332
320 # tm_suggestion becomes current.333 # tm_suggestion becomes current.
321 # Current for other context one stays the same.
322 self.assertTrue(tm is not None)334 self.assertTrue(tm is not None)
323 self.assertEquals(tm_suggestion, tm)335 self.assertEquals(tm_suggestion, tm)
336 # If a translation is set for the first time in upstream,
337 # this translation becomes current in Ubuntu too, but if the
338 # translation is set for the first time in Ubuntu, this does
339 # not affect the upstream translation.
340 expected_other = self.selectUpstreamTranslation(tm, tm_other)
324 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(341 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
325 tm, None, tm_other, [])342 tm, None, expected_other, [])
326343
327 def test_c_None__n_shared__o_shared__identical(self,344 def test_c_None__n_shared__o_shared__identical(self, follows=False):
328 follows=False):
329 # Current translation is None, and we have found a345 # Current translation is None, and we have found a
330 # shared existing TM matching new translations and it's346 # shared existing TM matching new translations and it's
331 # also a current translation in "other" context.347 # also a current translation in "other" context.
@@ -1147,6 +1163,10 @@
1147 self.potmsgset = self.factory.makePOTMsgSet(1163 self.potmsgset = self.factory.makePOTMsgSet(
1148 potemplate=potemplate, sequence=1)1164 potemplate=potemplate, sequence=1)
11491165
1166 def selectUpstreamTranslation(self, tm, tm_other):
1167 # See `SetCurrentTranslationTestMixin`
1168 return tm_other
1169
11501170
1151class TestSetCurrentTranslation_Upstream(SetCurrentTranslationTestMixin,1171class TestSetCurrentTranslation_Upstream(SetCurrentTranslationTestMixin,
1152 TestCaseWithFactory):1172 TestCaseWithFactory):
@@ -1182,3 +1202,7 @@
11821202
1183 self.potmsgset = self.factory.makePOTMsgSet(1203 self.potmsgset = self.factory.makePOTMsgSet(
1184 potemplate=potemplate, sequence=1)1204 potemplate=potemplate, sequence=1)
1205
1206 def selectUpstreamTranslation(self, tm, tm_other):
1207 # See `SetCurrentTranslationTestMixin`
1208 return tm