Merge lp:~abentley/launchpad/translation-fixing4 into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Approved by: Henning Eggers
Approved revision: no longer in the source branch.
Merged at revision: 12280
Proposed branch: lp:~abentley/launchpad/translation-fixing4
Merge into: lp:launchpad
Prerequisite: lp:~adeuring/launchpad/translation-fixing3
Diff against target: 443 lines (+64/-99)
11 files modified
lib/lp/testing/factory.py (+0/-28)
lib/lp/translations/doc/distroseries-translations-copy.txt (+12/-10)
lib/lp/translations/doc/potmsgset.txt (+15/-10)
lib/lp/translations/doc/rosetta-translation.txt (+2/-3)
lib/lp/translations/interfaces/potmsgset.py (+0/-6)
lib/lp/translations/model/potmsgset.py (+2/-7)
lib/lp/translations/model/translationmessage.py (+4/-4)
lib/lp/translations/scripts/message_sharing_migration.py (+7/-4)
lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt (+5/-2)
lib/lp/translations/tests/test_potmsgset.py (+7/-11)
lib/lp/translations/tests/test_translationmessage.py (+10/-14)
To merge this branch: bzr merge lp:~abentley/launchpad/translation-fixing4
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Deryck Hodge Pending
Review via email: mp+47461@code.launchpad.net

Description of the change

= Summary =
Update code to post-Recife APIs

== Proposed fix ==

== Pre-implementation notes ==
Discussed with henninge

== Implementation details ==
LaunchpadObjectFactory.makeTranslation removed
POTMsgSet.getImportedTranslationMessage removed
Many LaunchpadObjectFactory.makeSharedTranslationMessage call sites converted
Some POTMsgSet.getCurrentTranslationMessage call sites converted

A bit of lint fixed.

== Tests ==
bin/test -v

== Demo and Q/A ==
None

== Lint ==
None

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Woohoo! This is really great. I am grepping around for get*TranslationMessage and there are only a couple of them left. Same goes for updateTranslation: Only one occurrence left.

By the way, makeCurrentUbuntu and makeCurrentUpstream will be deleted, too. I had forgotten about those but they only have one or two call sites outside of updateTranslation which should be fixed easily.

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/testing/factory.py'
2--- lib/lp/testing/factory.py 2011-01-25 19:08:45 +0000
3+++ lib/lp/testing/factory.py 2011-01-25 20:40:05 +0000
4@@ -2728,34 +2728,6 @@
5 translations=translations, date_created=date_created)
6 return message.approveAsDiverged(pofile, reviewer)
7
8- def makeTranslation(self, pofile, sequence,
9- english=None, translated=None,
10- is_current_upstream=False):
11- """Add a single current translation entry to the given pofile.
12- This should only be used on pristine pofiles with pristine
13- potemplates to avoid conflicts in the sequence numbers.
14- For each entry a new POTMsgSet is created.
15-
16- :pofile: The pofile to add to.
17- :sequence: The sequence number for the POTMsgSet.
18- :english: The english string which becomes the msgid in the POTMsgSet.
19- :translated: The translated string which becomes the msgstr.
20- :is_current_upstream: The is_current_upstream flag of the
21- translation message.
22- """
23- if english is None:
24- english = self.getUniqueString('english')
25- if translated is None:
26- translated = self.getUniqueString('translated')
27- naked_pofile = removeSecurityProxy(pofile)
28- potmsgset = self.makePOTMsgSet(naked_pofile.potemplate, english,
29- sequence=sequence)
30- translation = removeSecurityProxy(
31- self.makeTranslationMessage(naked_pofile, potmsgset,
32- translations=[translated]))
33- translation.is_current_upstream = is_current_upstream
34- translation.is_current_ubuntu = True
35-
36 def makeTranslationImportQueueEntry(self, path=None, productseries=None,
37 distroseries=None,
38 sourcepackagename=None,
39
40=== modified file 'lib/lp/translations/doc/distroseries-translations-copy.txt'
41--- lib/lp/translations/doc/distroseries-translations-copy.txt 2010-12-02 16:13:51 +0000
42+++ lib/lp/translations/doc/distroseries-translations-copy.txt 2011-01-25 20:40:05 +0000
43@@ -1,4 +1,5 @@
44-= Migrating translations between distro series =
45+Migrating translations between distro series
46+============================================
47
48 When a new release series is created for a distribution it usually inherits
49 all settings and data from its parent (preceding) series. To facilitate this
50@@ -24,17 +25,15 @@
51 ... sourcepackagename=package.sourcepackagename,
52 ... name=name, translation_domain=name+'-domain')
53
54- >>> global_sequence = 1
55 >>> def makeTranslation(template, msgid, translations, sequence=None):
56- ... global global_sequence
57 ... if sequence is None:
58- ... sequence = global_sequence
59- ... global_sequence += 1
60+ ... sequence = factory.getUniqueInteger()
61 ... msgset = factory.makePOTMsgSet(template, msgid, sequence=sequence)
62 ... for language, translation in translations.items():
63 ... pofile = template.getPOFileByLang(language)
64- ... factory.makeSharedTranslationMessage(pofile, msgset,
65- ... translations=[translation], is_current_upstream=True)
66+ ... factory.makeCurrentTranslationMessage(
67+ ... pofile, msgset, translations=[translation],
68+ ... current_other=True)
69 ... return msgset
70
71 >>> package1 = makeSourcePackage('package1')
72@@ -69,7 +68,8 @@
73 >>> transaction_stub = FakeTransaction()
74
75
76-== Preconditions for migrating translations between distro series ==
77+Preconditions for migrating translations between distro series
78+==============================================================
79
80 Before we are able to migrate translations, there are a set of preconditions
81 that should be met:
82@@ -102,7 +102,8 @@
83 >>> carty.defer_translation_imports = True
84
85
86-== Performing the migration ==
87+Performing the migration
88+========================
89
90 A pristine distroseries can be filled with copies of translation templates
91 and translation files from the parent. The actual translations, stored in
92@@ -165,7 +166,8 @@
93 The child series must not yet have any translation templates.
94
95
96-== Running the script ==
97+Running the script
98+==================
99
100 Now, we execute the script that will do the migration using
101 copyTranslationsFromParent. For that we create a new child series to receive
102
103=== modified file 'lib/lp/translations/doc/potmsgset.txt'
104--- lib/lp/translations/doc/potmsgset.txt 2011-01-25 20:39:29 +0000
105+++ lib/lp/translations/doc/potmsgset.txt 2011-01-25 20:40:05 +0000
106@@ -234,8 +234,9 @@
107 >>> potmsgset.msgid_plural is None
108 True
109
110- >>> current = potmsgset.getCurrentTranslationMessage(
111- ... evolution_potemplate, pt_BR_dummypofile.language)
112+ >>> current = potmsgset.getCurrentTranslation(
113+ ... evolution_potemplate, pt_BR_dummypofile.language,
114+ ... evolution_potemplate.translation_side)
115 >>> print current
116 None
117 >>> pt_BR_dummy_current = potmsgset.getCurrentTranslationMessageOrDummy(
118@@ -503,15 +504,17 @@
119 >>> evo_product_message = evo_product_template.getPOTMsgSetByMsgIDText(
120 ... ' cards')
121 >>> evo_product_translation = (
122- ... evo_product_message.getCurrentTranslationMessage(
123- ... evo_product_template, spanish))
124+ ... evo_product_message.getCurrentTranslation(
125+ ... evo_product_template, spanish,
126+ ... evo_product_template.translation_side))
127 >>> evo_product_translation.translations
128 [u' tarjetas']
129 >>> evo_distro_message = evo_distro_template.getPOTMsgSetByMsgIDText(
130 ... ' cards')
131 >>> evo_distro_translation = (
132- ... evo_distro_message.getCurrentTranslationMessage(
133- ... evo_distro_template, spanish))
134+ ... evo_distro_message.getCurrentTranslation(
135+ ... evo_distro_template, spanish,
136+ ... evo_distro_template.translation_side))
137 >>> evo_distro_translation.translations
138 [u' caratas']
139
140@@ -599,8 +602,9 @@
141 >>> pofile = evo_man_template.getPOFileByLang('es')
142 >>> print pofile.title
143 Spanish (es) translation of man in Ubuntu Hoary package "evolution"
144- >>> current = potmsgset_translated.getCurrentTranslationMessage(
145- ... evo_man_template, pofile.language)
146+ >>> current = potmsgset_translated.getCurrentTranslation(
147+ ... evo_man_template, pofile.language,
148+ ... evo_man_template.translation_side)
149 >>> print current.translations
150 [u'just a translation']
151
152@@ -635,8 +639,9 @@
153 Given that it doesn't exist in our database, is impossible to have a
154 submission already for it.
155
156- >>> current = potmsgset_untranslated.getCurrentTranslationMessage(
157- ... pmount_man_template, pofile.language)
158+ >>> current = potmsgset_untranslated.getCurrentTranslation(
159+ ... pmount_man_template, pofile.language,
160+ ... pmount_man_template.translation_side)
161 >>> print current
162 None
163 >>> imported = potmsgset_untranslated.getOtherTranslation(
164
165=== modified file 'lib/lp/translations/doc/rosetta-translation.txt'
166--- lib/lp/translations/doc/rosetta-translation.txt 2011-01-25 20:39:29 +0000
167+++ lib/lp/translations/doc/rosetta-translation.txt 2011-01-25 20:40:05 +0000
168@@ -46,7 +46,6 @@
169
170 Add a translation.
171
172- >>> import datetime
173 >>> import pytz
174 >>> UTC = pytz.timezone('UTC')
175 >>> message = factory.makeCurrentTranslationMessage(
176@@ -118,8 +117,8 @@
177 >>> upstream_message.msgstr0.translation == u'bar'
178 True
179
180- >>> potmsgset.getImportedTranslationMessage(
181- ... template, spanish) == upstream_message
182+ >>> potmsgset.getCurrentTranslation(
183+ ... template, spanish, template.translation_side) == upstream_message
184 True
185
186 Excellent. This shows that activating a new upstream translation upon
187
188=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
189--- lib/lp/translations/interfaces/potmsgset.py 2011-01-24 15:51:18 +0000
190+++ lib/lp/translations/interfaces/potmsgset.py 2011-01-25 20:40:05 +0000
191@@ -148,12 +148,6 @@
192 Diverged messages are preferred.
193 """
194
195- def getImportedTranslationMessage(potemplate, language):
196- """Returns a TranslationMessage as imported from the package.
197-
198- Diverged messages are preferred.
199- """
200-
201 def getSharedTranslationMessage(language):
202 """Returns a shared TranslationMessage."""
203
204
205=== modified file 'lib/lp/translations/model/potmsgset.py'
206--- lib/lp/translations/model/potmsgset.py 2011-01-14 13:03:40 +0000
207+++ lib/lp/translations/model/potmsgset.py 2011-01-25 20:40:05 +0000
208@@ -320,11 +320,6 @@
209 return self._getUsedTranslationMessage(
210 potemplate, language, current=True)
211
212- def getImportedTranslationMessage(self, potemplate, language):
213- """See `IPOTMsgSet`."""
214- return self._getUsedTranslationMessage(
215- potemplate, language, current=False)
216-
217 def getSharedTranslationMessage(self, language):
218 """See `IPOTMsgSet`."""
219 return self._getUsedTranslationMessage(
220@@ -890,8 +885,8 @@
221 matching_message is not None and
222 matching_message.is_current_upstream)
223 if is_current_upstream or match_is_upstream:
224- upstream_message = self.getImportedTranslationMessage(
225- pofile.potemplate, pofile.language)
226+ upstream_message = self.getCurrentTranslation(
227+ pofile.potemplate, pofile.language, TranslationSide.UPSTREAM)
228 else:
229 upstream_message = None
230
231
232=== modified file 'lib/lp/translations/model/translationmessage.py'
233--- lib/lp/translations/model/translationmessage.py 2011-01-05 14:31:05 +0000
234+++ lib/lp/translations/model/translationmessage.py 2011-01-25 20:40:05 +0000
235@@ -475,8 +475,8 @@
236 def makeCurrentUbuntu(self, new_value=True):
237 """See `ITranslationMessage`."""
238 if new_value and not self.is_current_ubuntu:
239- incumbent = self.potmsgset.getCurrentTranslationMessage(
240- self.potemplate, self.language)
241+ incumbent = self.potmsgset.getCurrentTranslation(
242+ self.potemplate, self.language, TranslationSide.UBUNTU)
243 if incumbent == self:
244 return
245 if (incumbent is not None and
246@@ -490,8 +490,8 @@
247 def makeCurrentUpstream(self, new_value=True):
248 """See `ITranslationMessage`."""
249 if new_value and not self.is_current_upstream:
250- incumbent = self.potmsgset.getImportedTranslationMessage(
251- self.potemplate, self.language)
252+ incumbent = self.potmsgset.getCurrentTranslationMessage(
253+ self.potemplate, self.language, TranslationSide.UPSTREAM)
254 if incumbent == self:
255 return
256 if (incumbent is not None and
257
258=== modified file 'lib/lp/translations/scripts/message_sharing_migration.py'
259--- lib/lp/translations/scripts/message_sharing_migration.py 2010-12-16 14:43:08 +0000
260+++ lib/lp/translations/scripts/message_sharing_migration.py 2011-01-25 20:40:05 +0000
261@@ -23,6 +23,7 @@
262 LaunchpadScriptFailure,
263 )
264 from lp.translations.interfaces.potemplate import IPOTemplateSet
265+from lp.translations.interfaces.side import TranslationSide
266 from lp.translations.interfaces.translations import TranslationConstants
267 from lp.translations.model.potmsgset import POTMsgSet
268 from lp.translations.model.translationmessage import TranslationMessage
269@@ -597,15 +598,17 @@
270 """
271 clashing_current = None
272 if message.is_current_ubuntu:
273- found = target_potmsgset.getCurrentTranslationMessage(
274- potemplate=target_potemplate, language=message.language)
275+ found = target_potmsgset.getCurrentTranslation(
276+ potemplate=target_potemplate, language=message.language,
277+ side=TranslationSide.UBUNTU)
278 if found is not None and found.potemplate == target_potemplate:
279 clashing_current = found
280
281 clashing_imported = None
282 if message.is_current_upstream:
283- found = target_potmsgset.getImportedTranslationMessage(
284- potemplate=target_potemplate, language=message.language)
285+ found = target_potmsgset.getCurrentTranslation(
286+ potemplate=target_potemplate, language=message.language,
287+ side=TranslationSide.UPSTREAM)
288 if found is not None and found.potemplate == target_potemplate:
289 clashing_imported = found
290
291
292=== modified file 'lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt'
293--- lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt 2010-12-16 13:16:58 +0000
294+++ lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt 2011-01-25 20:40:05 +0000
295@@ -540,6 +540,7 @@
296 >>> from lp.registry.interfaces.sourcepackagename import (
297 ... ISourcePackageNameSet)
298 >>> from lp.translations.interfaces.potemplate import IPOTemplateSet
299+ >>> from lp.translations.interfaces.side import TranslationSide
300 >>> login("carlos@canonical.com")
301 >>> carlos = getUtility(IPersonSet).getByName('carlos')
302
303@@ -552,8 +553,10 @@
304 >>> evolution_pofile = evolution_potemplate.getPOFileByLang('es')
305 >>> potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(' cards')
306 >>> spanish = evolution_pofile.language
307- >>> imported = potmsgset.getImportedTranslationMessage(
308- ... evolution_potemplate, spanish)
309+
310+ >>> imported = potmsgset.getCurrentTranslation(
311+ ... evolution_potemplate, spanish,
312+ ... side=TranslationSide.UPSTREAM)
313 >>> imported.translations
314 [u' tarjetas']
315
316
317=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
318--- lib/lp/translations/tests/test_potmsgset.py 2011-01-25 20:39:29 +0000
319+++ lib/lp/translations/tests/test_potmsgset.py 2011-01-25 20:40:05 +0000
320@@ -365,9 +365,8 @@
321
322 # If there is an imported translation on the external POTMsgSet,
323 # it is returned as the externally used suggestion.
324- imported_translation = self.factory.makeSharedTranslationMessage(
325- pofile=external_pofile, potmsgset=external_potmsgset,
326- is_current_upstream=True)
327+ imported_translation = self.factory.makeCurrentTranslationMessage(
328+ pofile=external_pofile, potmsgset=external_potmsgset)
329 imported_translation.makeCurrentUbuntu(False)
330
331 transaction.commit()
332@@ -425,11 +424,8 @@
333
334 # If there is an imported, non-current translation on the external
335 # POTMsgSet, it is not returned as the external suggestion.
336- imported_translation = self.factory.makeSharedTranslationMessage(
337- pofile=external_pofile, potmsgset=external_potmsgset,
338- is_current_upstream=True)
339- imported_translation.makeCurrentUbuntu(False)
340-
341+ imported_translation = self.factory.makeCurrentTranslationMessage(
342+ pofile=external_pofile, potmsgset=external_potmsgset)
343 transaction.commit()
344
345 self.assertEquals(
346@@ -1279,9 +1275,9 @@
347 pofile, potmsgset = self._makePOFileAndPOTMsgSet()
348 owner = pofile.potemplate.owner
349 translation = {0: self.factory.getUniqueString()}
350- shared_message = self.factory.makeSharedTranslationMessage(
351+ shared_message = self.factory.makeCurrentTranslationMessage(
352 pofile=pofile, potmsgset=potmsgset, translator=owner,
353- translations=translation)
354+ translations=translation, current_other=True)
355 self.assertTrue(shared_message.is_current_ubuntu)
356
357 suggestion = potmsgset.submitSuggestion(pofile, owner, translation)
358@@ -1330,7 +1326,7 @@
359 owner = pofile.potemplate.owner
360 translation = {0: self.factory.getUniqueString()}
361 translation2 = {0: self.factory.getUniqueString()}
362- shared_message = self.factory.makeSharedTranslationMessage(
363+ shared_message = self.factory.makeCurrentTranslationMessage(
364 pofile=pofile, potmsgset=potmsgset, translator=owner,
365 translations=translation)
366 diverged_message = self.factory.makeCurrentTranslationMessage(
367
368=== modified file 'lib/lp/translations/tests/test_translationmessage.py'
369--- lib/lp/translations/tests/test_translationmessage.py 2011-01-14 13:03:40 +0000
370+++ lib/lp/translations/tests/test_translationmessage.py 2011-01-25 20:40:05 +0000
371@@ -80,8 +80,7 @@
372 # There is a suggestion for it. The suggestion gets approved,
373 # and thereby becomes the message's current translation.
374 pofile = self.factory.makePOFile('br')
375- suggestion = self.factory.makeSharedTranslationMessage(
376- pofile=pofile, suggestion=True)
377+ suggestion = self.factory.makeSuggestion(pofile=pofile)
378 reviewer = self.factory.makePerson()
379 self.assertFalse(suggestion.is_current_upstream)
380 self.assertFalse(suggestion.is_current_ubuntu)
381@@ -97,8 +96,8 @@
382 # If there was already a current translation, it is disabled
383 # when a suggestion is approved.
384 pofile, potmsgset = self.factory.makePOFileAndPOTMsgSet('te')
385- suggestion = self.factory.makeSharedTranslationMessage(
386- pofile=pofile, potmsgset=potmsgset, suggestion=True)
387+ suggestion = self.factory.makeSuggestion(
388+ pofile=pofile, potmsgset=potmsgset)
389 incumbent_message = self.factory.makeCurrentTranslationMessage(
390 pofile=pofile, potmsgset=potmsgset)
391
392@@ -176,8 +175,7 @@
393 # details) the approval can be made to propagate to the other
394 # side, subject to the share_with_other_side parameter.
395 pofile = self.factory.makePOFile('ki')
396- suggestion = self.factory.makeSharedTranslationMessage(
397- pofile=pofile, suggestion=True)
398+ suggestion = self.factory.makeSuggestion(pofile=pofile)
399 reviewer = self.factory.makePerson()
400
401 self.assertFalse(suggestion.is_current_upstream)
402@@ -191,8 +189,7 @@
403 def test_approve_marks_reviewed(self):
404 # Approving a suggestion updates its review fields.
405 pofile = self.factory.makePOFile('ko')
406- suggestion = self.factory.makeSharedTranslationMessage(
407- pofile=pofile, suggestion=True)
408+ suggestion = self.factory.makeSuggestion(pofile=pofile)
409 reviewer = self.factory.makePerson()
410
411 self.assertIs(None, suggestion.reviewer)
412@@ -220,8 +217,7 @@
413 # A reviewer receives karma for approving suggestions.
414 reviewer = self.factory.makePerson()
415 pofile = self.factory.makePOFile('be')
416- suggestion = self.factory.makeSharedTranslationMessage(
417- pofile=pofile, suggestion=True)
418+ suggestion = self.factory.makeSuggestion(pofile=pofile)
419
420 karmarecorder = self.installKarmaRecorder(person=reviewer)
421 suggestion.approve(pofile, reviewer)
422@@ -234,8 +230,8 @@
423 # A translator receives karma for suggestions that are approved.
424 translator = self.factory.makePerson()
425 pofile = self.factory.makePOFile('ba')
426- suggestion = self.factory.makeSharedTranslationMessage(
427- pofile=pofile, translator=translator, suggestion=True)
428+ suggestion = self.factory.makeSuggestion(
429+ pofile=pofile, translator=translator)
430
431 karmarecorder = self.installKarmaRecorder(person=translator)
432 suggestion.approve(pofile, self.factory.makePerson())
433@@ -250,8 +246,8 @@
434 # suggestion.
435 translator = self.factory.makePerson()
436 pofile = self.factory.makePOFile('bi')
437- suggestion = self.factory.makeSharedTranslationMessage(
438- pofile=pofile, translator=translator, suggestion=True)
439+ suggestion = self.factory.makeSuggestion(
440+ pofile=pofile, translator=translator)
441
442 karmarecorder = self.installKarmaRecorder(person=translator)
443 suggestion.approve(pofile, translator)