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
1=== modified file 'lib/lp/translations/model/potmsgset.py'
2--- lib/lp/translations/model/potmsgset.py 2011-02-04 17:14:20 +0000
3+++ lib/lp/translations/model/potmsgset.py 2011-02-15 11:46:10 +0000
4@@ -1028,6 +1028,16 @@
5 self, pofile.potemplate, pofile.language))
6 if other_incumbent is None:
7 traits.other_side_traits.setFlag(message, True)
8+ elif (incumbent_message is None and
9+ traits.side == TranslationSide.UPSTREAM):
10+ # If this is the first upstream translation, we
11+ # we use it as the current Ubuntu translation
12+ # too, overriding a possibly existing current
13+ # Ubuntu translation.
14+ if other_incumbent is not None:
15+ traits.other_side_traits.setFlag(
16+ other_incumbent, False)
17+ traits.other_side_traits.setFlag(message, True)
18 elif character == '+':
19 if share_with_other_side:
20 traits.other_side_traits.setFlag(incumbent_message, False)
21
22=== modified file 'lib/lp/translations/tests/test_setcurrenttranslation.py'
23--- lib/lp/translations/tests/test_setcurrenttranslation.py 2010-11-18 04:08:16 +0000
24+++ lib/lp/translations/tests/test_setcurrenttranslation.py 2011-02-15 11:46:10 +0000
25@@ -161,6 +161,12 @@
26 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
27 tm, None, tm, [])
28
29+ def selectUpstreamTranslation(self, tm, tm_other):
30+ # Return the upstream translation.
31+ # :param tm: A translation for this side.
32+ # :param tm_other: A translation for the other side.
33+ raise NotImplementedError
34+
35 def test_c_None__n_None__o_shared(self, follows=False):
36 # Current translation is None, and we have found no
37 # existing TM matching new translations.
38@@ -175,10 +181,17 @@
39 new_translations, share_with_other_side=follows)
40
41 # We end up with a shared current translation.
42- # Current for other context one stays the same.
43+ # Current for other context one stays the same, if the
44+ # other side does not follow this side.
45 self.assertTrue(tm is not None)
46+ if follows:
47+ # Even if the other side is supposed to follow this side,
48+ # we ovverride the other only if the current side is Ubuntu.
49+ expected_other = self.selectUpstreamTranslation(tm, tm_other)
50+ else:
51+ expected_other = tm_other
52 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
53- tm, None, tm_other, [])
54+ tm, None, expected_other, [])
55
56 def test_c_None__n_None__o_shared__follows(self):
57 # There is no current translation, though there is a shared one
58@@ -318,14 +331,17 @@
59 new_translations, share_with_other_side=True)
60
61 # tm_suggestion becomes current.
62- # Current for other context one stays the same.
63 self.assertTrue(tm is not None)
64 self.assertEquals(tm_suggestion, tm)
65+ # If a translation is set for the first time in upstream,
66+ # this translation becomes current in Ubuntu too, but if the
67+ # translation is set for the first time in Ubuntu, this does
68+ # not affect the upstream translation.
69+ expected_other = self.selectUpstreamTranslation(tm, tm_other)
70 self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
71- tm, None, tm_other, [])
72+ tm, None, expected_other, [])
73
74- def test_c_None__n_shared__o_shared__identical(self,
75- follows=False):
76+ def test_c_None__n_shared__o_shared__identical(self, follows=False):
77 # Current translation is None, and we have found a
78 # shared existing TM matching new translations and it's
79 # also a current translation in "other" context.
80@@ -1147,6 +1163,10 @@
81 self.potmsgset = self.factory.makePOTMsgSet(
82 potemplate=potemplate, sequence=1)
83
84+ def selectUpstreamTranslation(self, tm, tm_other):
85+ # See `SetCurrentTranslationTestMixin`
86+ return tm_other
87+
88
89 class TestSetCurrentTranslation_Upstream(SetCurrentTranslationTestMixin,
90 TestCaseWithFactory):
91@@ -1182,3 +1202,7 @@
92
93 self.potmsgset = self.factory.makePOTMsgSet(
94 potemplate=potemplate, sequence=1)
95+
96+ def selectUpstreamTranslation(self, tm, tm_other):
97+ # See `SetCurrentTranslationTestMixin`
98+ return tm