Merge lp:~henninge/launchpad/bug-456498 into lp:launchpad
- bug-456498
- Merge into devel
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Brad Crittenden | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~henninge/launchpad/bug-456498 | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
447 lines 4 files modified
lib/lp/translations/doc/potmsgset.txt (+53/-18) lib/lp/translations/interfaces/potmsgset.py (+36/-1) lib/lp/translations/model/pofile.py (+20/-21) lib/lp/translations/model/potmsgset.py (+28/-16) |
||||
To merge this branch: | bzr merge lp:~henninge/launchpad/bug-456498 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brad Crittenden (community) | code | Approve | |
Review via email: mp+13668@code.launchpad.net |
Commit message
Description of the change
Henning Eggers (henninge) wrote : | # |
Brad Crittenden (bac) wrote : | # |
Hi Henning,
* Please whack line 5 and just use pytz.UTC throughout.
* You agreed to reword the sentence at line 12 to read better.
* We also discussed biting the bullet and making the trans_credit_type an enum since having the magic strings scattered around make me a little queasy. I think/hope you'll find it isn't much worse.
I'm marking this Needs Fixing and ask that you paste an incremental diff so we can determine if it was worth the effort.
Thanks for the branch Henning.
Henning Eggers (henninge) wrote : | # |
Hi Brad,
here is the patch with the changes. It has gotten lengthier because or the pytz.UTC change and because I ordered some imports properly.
Thank you for the review and prodding me to do this properly using and enum. Danilo is thrilled! ;-)
Henning
Henning Eggers (henninge) wrote : | # |
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -25,43 +25,43 @@
>>> from datetime import datetime
>>> import pytz
- >>> UTC = pytz.timezone(
== POTMsgSet.
-A POTMsgSet can be a translation credit. These have special msgids that may
-differ for historical reason for the same type of credit. Two methods detect
-gloss over these different msgids.
+A POTMsgSet can be translation credits. These have special msgids that may
+differ for historical reason for the same type of credit. The property
+is_translation
+property translation_
>>> def print_credit(
... print credit.
- ... print credit.
+ ... print credit.
>>> print_credit(
False
- None
+ Not a translation credits message
>>> print_credit(
... potemplate, singular=
True
- translator-credits
+ Gnome credits message
>>> print_credit(
... potemplate, singular=
True
- translator-credits
+ Gnome credits message
>>> print_credit(
... potemplate,
... singular=u'Your emails', context=u'EMAIL OF TRANSLATORS'))
True
- Your emails
+ KDE emails credits message
>>> print_credit(
... potemplate, singular=u'_: EMAIL OF TRANSLATORS\nYour emails'))
True
- Your emails
+ KDE emails credits message
== POTMsgSet.
@@ -256,7 +256,7 @@
>>> new_translation = upstream_
... carlos, {0: u'foo'}, is_imported=False, force_suggestio
- ... lock_timestamp=
+ ... lock_timestamp=
Since this message is just a suggestion, it doesn't have a reviewer, but
it does note a person which last changed it.
@@ -301,7 +301,7 @@
>>> new_translation = upstream_
... upstream_pofile, carlos, {0: u'foo %d', 1: u'foos %d'},
- ... is_imported=True, lock_timestamp=
+ ... is_imported=True, lock_timestamp=
The new translation is reflected in the POFile statistics.
@@ -330,7 +330,7 @@
... u'have ')
>>> new_translation = upstream_
... upstream_pofile, carlos, {0: u''},
- ... is_imported=True, lock_timestamp=
+ ... is_imported=True, lock_timestamp=
Current translation is now unset, as is imported.
@@ -354,7 +354,7 @@
... u'%d contact', u'%d contacts')
>>> new_translation = upstream_
... ...
Brad Crittenden (bac) wrote : | # |
Henning this incremental diff looks fantastic! Thanks for making the change.
Not to be too immodest, but this conversation we just had is what peer code reviews should be: discourse-driven, collaborative, respectful and successful in that the resulting code is improved. Thanks for making it happen.
Preview Diff
1 | === modified file 'lib/lp/translations/doc/potmsgset.txt' |
2 | --- lib/lp/translations/doc/potmsgset.txt 2009-07-02 17:16:50 +0000 |
3 | +++ lib/lp/translations/doc/potmsgset.txt 2009-10-21 10:17:14 +0000 |
4 | @@ -25,7 +25,43 @@ |
5 | |
6 | >>> from datetime import datetime |
7 | >>> import pytz |
8 | - >>> UTC = pytz.timezone('UTC') |
9 | + |
10 | + |
11 | +== POTMsgSet.is_translation_credit and POTMsgSet.translation_credit_type == |
12 | + |
13 | +A POTMsgSet can be translation credits. These have special msgids that may |
14 | +differ for historical reason for the same type of credit. The property |
15 | +is_translation_credit indicates if the POTMsgSet is translation credits. The |
16 | +property translation_credit_type contains the type of translation credits. |
17 | + |
18 | + >>> def print_credit(credit): |
19 | + ... print credit.is_translation_credit |
20 | + ... print credit.translation_credits_type.title |
21 | + |
22 | + >>> print_credit(factory.makePOTMsgSet(potemplate)) |
23 | + False |
24 | + Not a translation credits message |
25 | + |
26 | + >>> print_credit(factory.makePOTMsgSet( |
27 | + ... potemplate, singular=u'translator-credits')) |
28 | + True |
29 | + Gnome credits message |
30 | + |
31 | + >>> print_credit(factory.makePOTMsgSet( |
32 | + ... potemplate, singular=u'translation-credits')) |
33 | + True |
34 | + Gnome credits message |
35 | + |
36 | + >>> print_credit(factory.makePOTMsgSet( |
37 | + ... potemplate, |
38 | + ... singular=u'Your emails', context=u'EMAIL OF TRANSLATORS')) |
39 | + True |
40 | + KDE emails credits message |
41 | + |
42 | + >>> print_credit(factory.makePOTMsgSet( |
43 | + ... potemplate, singular=u'_: EMAIL OF TRANSLATORS\nYour emails')) |
44 | + True |
45 | + KDE emails credits message |
46 | |
47 | |
48 | == POTMsgSet.normalizeWhitespaces == |
49 | @@ -220,7 +256,7 @@ |
50 | |
51 | >>> new_translation = upstream_potmsgset.updateTranslation(upstream_pofile, |
52 | ... carlos, {0: u'foo'}, is_imported=False, force_suggestion=True, |
53 | - ... lock_timestamp=datetime.now(UTC)) |
54 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
55 | |
56 | Since this message is just a suggestion, it doesn't have a reviewer, but |
57 | it does note a person which last changed it. |
58 | @@ -265,7 +301,7 @@ |
59 | |
60 | >>> new_translation = upstream_potmsgset.updateTranslation( |
61 | ... upstream_pofile, carlos, {0: u'foo %d', 1: u'foos %d'}, |
62 | - ... is_imported=True, lock_timestamp=datetime.now(UTC)) |
63 | + ... is_imported=True, lock_timestamp=datetime.now(pytz.UTC)) |
64 | |
65 | The new translation is reflected in the POFile statistics. |
66 | |
67 | @@ -294,7 +330,7 @@ |
68 | ... u'have ') |
69 | >>> new_translation = upstream_potmsgset.updateTranslation( |
70 | ... upstream_pofile, carlos, {0: u''}, |
71 | - ... is_imported=True, lock_timestamp=datetime.now(UTC)) |
72 | + ... is_imported=True, lock_timestamp=datetime.now(pytz.UTC)) |
73 | |
74 | Current translation is now unset, as is imported. |
75 | |
76 | @@ -318,7 +354,7 @@ |
77 | ... u'%d contact', u'%d contacts') |
78 | >>> new_translation = upstream_potmsgset.updateTranslation( |
79 | ... upstream_pofile, carlos, {0: u'', 1: u''}, |
80 | - ... is_imported=True, lock_timestamp=datetime.now(UTC)) |
81 | + ... is_imported=True, lock_timestamp=datetime.now(pytz.UTC)) |
82 | |
83 | The statistics change to reflect that the message is not available |
84 | in upstream anymore, so it's now noted as newly translated in Launchpad. |
85 | @@ -353,7 +389,7 @@ |
86 | |
87 | >>> new_message = potmsgset.updateTranslation( |
88 | ... pofile_es, no_priv, {0: u'test string'}, |
89 | - ... is_imported=False, lock_timestamp=datetime.now(UTC)) |
90 | + ... is_imported=False, lock_timestamp=datetime.now(pytz.UTC)) |
91 | |
92 | This message is not made current or marked as imported. |
93 | |
94 | @@ -391,7 +427,7 @@ |
95 | |
96 | >>> new_message = potmsgset.updateTranslation( |
97 | ... pofile_es, foobar, {0: u'test string'}, |
98 | - ... is_imported=False, lock_timestamp=datetime.now(UTC)) |
99 | + ... is_imported=False, lock_timestamp=datetime.now(pytz.UTC)) |
100 | |
101 | We don't have any suggestion newer than the new active translation |
102 | |
103 | @@ -500,12 +536,12 @@ |
104 | 2 |
105 | >>> message = plural_potmsgset.updateTranslation(pofile_es, foobar, |
106 | ... {0: u'foo %d', 1: None}, is_imported=False, |
107 | - ... lock_timestamp=datetime.now(UTC)) |
108 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
109 | >>> message.is_complete |
110 | False |
111 | >>> message = plural_potmsgset.updateTranslation(pofile_es, foobar, |
112 | ... {0: None}, is_imported=False, |
113 | - ... lock_timestamp=datetime.now(UTC)) |
114 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
115 | >>> message.is_complete |
116 | False |
117 | |
118 | @@ -537,7 +573,7 @@ |
119 | |
120 | >>> message_with_two_forms = pm_potmsgset.updateTranslation( |
121 | ... pm_translation, pm_template.owner, ['%d fu', '%d fuitl'], |
122 | - ... is_imported=False, lock_timestamp=datetime.now(UTC)) |
123 | + ... is_imported=False, lock_timestamp=datetime.now(pytz.UTC)) |
124 | |
125 | When an otherwise identical translation with three comes along, the |
126 | third form is ignored because it falls outside the current 2 forms. |
127 | @@ -546,7 +582,7 @@ |
128 | >>> message_with_three_forms = pm_potmsgset.updateTranslation( |
129 | ... pm_translation, pm_template.owner, |
130 | ... ['%d fu', '%d fuitl', '%d fuitlx'], is_imported=False, |
131 | - ... lock_timestamp=datetime.now(UTC)) |
132 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
133 | >>> message_with_three_forms == message_with_two_forms |
134 | True |
135 | |
136 | @@ -560,7 +596,7 @@ |
137 | >>> message_with_three_forms = pm_potmsgset.updateTranslation( |
138 | ... pm_translation, pm_template.owner, |
139 | ... ['%d fu', '%d fuitl', '%d fuitlx'], is_imported=False, |
140 | - ... lock_timestamp=datetime.now(UTC)) |
141 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
142 | >>> message_with_three_forms == message_with_two_forms |
143 | False |
144 | |
145 | @@ -575,7 +611,7 @@ |
146 | |
147 | >>> message_with_one_form = pm_potmsgset.updateTranslation( |
148 | ... pm_translation, pm_template.owner, ['%d fu'], |
149 | - ... is_imported=False, lock_timestamp=datetime.now(UTC)) |
150 | + ... is_imported=False, lock_timestamp=datetime.now(pytz.UTC)) |
151 | WARNING:...Translation for POTMsgSet ... into 'zap' matches |
152 | 2 existing translations. |
153 | |
154 | @@ -591,17 +627,16 @@ |
155 | This method tells us whether the active translation was reviewed after |
156 | the given timestamp. |
157 | |
158 | - >>> from pytz import UTC |
159 | >>> translationmessage = TranslationMessage.get(2) |
160 | >>> potmsgset = translationmessage.potmsgset |
161 | >>> pofile = translationmessage.pofile |
162 | >>> translationmessage.date_reviewed.isoformat() |
163 | '2005-04-07T13:19:17.601068+00:00' |
164 | >>> potmsgset.isTranslationNewerThan(pofile, |
165 | - ... datetime(2004, 11, 30, 7, 0, 0, tzinfo=UTC)) |
166 | + ... datetime(2004, 11, 30, 7, 0, 0, tzinfo=pytz.UTC)) |
167 | True |
168 | >>> potmsgset.isTranslationNewerThan(pofile, |
169 | - ... datetime(2006, 11, 30, 7, 0, 0, tzinfo=UTC)) |
170 | + ... datetime(2006, 11, 30, 7, 0, 0, tzinfo=pytz.UTC)) |
171 | False |
172 | |
173 | |
174 | @@ -951,7 +986,7 @@ |
175 | |
176 | >>> new_translation = potmsgset.updateTranslation(pofile_es_variant, |
177 | ... carlos, {0: u'test variant translation\n'}, |
178 | - ... is_imported=True, lock_timestamp=datetime.now(UTC)) |
179 | + ... is_imported=True, lock_timestamp=datetime.now(pytz.UTC)) |
180 | |
181 | A new translation is saved in the PO file. |
182 | |
183 | @@ -1007,7 +1042,7 @@ |
184 | |
185 | >>> new_translation = translator_credits.updateTranslation(spanish_pofile, |
186 | ... carlos, {0: u'Some Translator'}, is_imported=True, |
187 | - ... lock_timestamp=datetime.now(UTC)) |
188 | + ... lock_timestamp=datetime.now(pytz.UTC)) |
189 | |
190 | >>> current = translator_credits.getCurrentTranslationMessage( |
191 | ... alsa_potemplate, spanish) |
192 | |
193 | === modified file 'lib/lp/translations/interfaces/potmsgset.py' |
194 | --- lib/lp/translations/interfaces/potmsgset.py 2009-08-25 20:15:38 +0000 |
195 | +++ lib/lp/translations/interfaces/potmsgset.py 2009-10-21 10:17:14 +0000 |
196 | @@ -4,7 +4,8 @@ |
197 | # pylint: disable-msg=E0211,E0213 |
198 | |
199 | from zope.interface import Interface, Attribute |
200 | -from zope.schema import Bool, Int, Object, Text |
201 | +from zope.schema import Bool, Choice, Int, Object, Text |
202 | +from lazr.enum import EnumeratedType, Item |
203 | |
204 | from canonical.launchpad import _ |
205 | from lp.translations.interfaces.pomsgid import IPOMsgID |
206 | @@ -15,9 +16,38 @@ |
207 | 'IPOTMsgSet', |
208 | 'BrokenTextError', |
209 | 'POTMsgSetInIncompatibleTemplatesError', |
210 | + 'TranslationCreditsType', |
211 | ] |
212 | |
213 | |
214 | +class TranslationCreditsType(EnumeratedType): |
215 | + """Identify a POTMsgSet as translation credits.""" |
216 | + |
217 | + NOT_CREDITS = Item(""" |
218 | + Not a translation credits message |
219 | + |
220 | + This is a standard msgid and not translation credits. |
221 | + """) |
222 | + |
223 | + GNOME = Item(""" |
224 | + Gnome credits message |
225 | + |
226 | + How they do them in Gnome. |
227 | + """) |
228 | + |
229 | + KDE_EMAILS = Item(""" |
230 | + KDE emails credits message |
231 | + |
232 | + How they do them in KDE for translator emails. |
233 | + """) |
234 | + |
235 | + KDE_NAMES = Item(""" |
236 | + KDE names credits message |
237 | + |
238 | + How they do them in KDE for translator names. |
239 | + """) |
240 | + |
241 | + |
242 | class BrokenTextError(ValueError): |
243 | """Exception raised when we detect values on a text that aren't valid.""" |
244 | |
245 | @@ -251,6 +281,11 @@ |
246 | is_translation_credit = Attribute( |
247 | """Whether this is a message set for crediting translators.""") |
248 | |
249 | + translation_credits_type = Choice( |
250 | + title=u"The type of translation credit of this message.", |
251 | + required=True, |
252 | + vocabulary = TranslationCreditsType) |
253 | + |
254 | def makeHTMLID(suffix=None): |
255 | """Unique name for this `POTMsgSet` for use in HTML element ids. |
256 | |
257 | |
258 | === modified file 'lib/lp/translations/model/pofile.py' |
259 | --- lib/lp/translations/model/pofile.py 2009-09-09 11:04:58 +0000 |
260 | +++ lib/lp/translations/model/pofile.py 2009-10-21 10:17:14 +0000 |
261 | @@ -30,20 +30,16 @@ |
262 | from canonical.database.sqlbase import ( |
263 | SQLBase, flush_database_updates, quote, quote_like, sqlvalues) |
264 | from canonical.launchpad import helpers |
265 | -from lp.translations.utilities.rosettastats import RosettaStats |
266 | -from lp.registry.interfaces.person import validate_public_person |
267 | -from lp.translations.model.potmsgset import POTMsgSet |
268 | -from lp.translations.model.translationimportqueue import ( |
269 | - collect_import_info) |
270 | -from lp.translations.model.translationmessage import ( |
271 | - TranslationMessage, make_plurals_sql_fragment) |
272 | -from lp.translations.model.translationtemplateitem import ( |
273 | - TranslationTemplateItem) |
274 | from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities |
275 | from canonical.launchpad.webapp.interfaces import ( |
276 | IStoreSelector, MAIN_STORE, MASTER_FLAVOR) |
277 | +from canonical.launchpad.webapp.publisher import canonical_url |
278 | +from canonical.librarian.interfaces import ILibrarianClient |
279 | +from lp.registry.interfaces.person import validate_public_person |
280 | +from lp.translations.utilities.rosettastats import RosettaStats |
281 | from lp.translations.interfaces.pofile import IPOFile, IPOFileSet |
282 | -from lp.translations.interfaces.potmsgset import BrokenTextError |
283 | +from lp.translations.interfaces.potmsgset import ( |
284 | + BrokenTextError, TranslationCreditsType) |
285 | from lp.translations.interfaces.translationcommonformat import ( |
286 | ITranslationFileData) |
287 | from lp.translations.interfaces.translationexporter import ( |
288 | @@ -61,11 +57,16 @@ |
289 | from lp.translations.interfaces.translationsperson import ( |
290 | ITranslationsPerson) |
291 | from lp.translations.interfaces.translations import TranslationConstants |
292 | +from lp.translations.model.potmsgset import POTMsgSet |
293 | +from lp.translations.model.translationimportqueue import ( |
294 | + collect_import_info) |
295 | from lp.translations.model.translatablemessage import TranslatableMessage |
296 | +from lp.translations.model.translationmessage import ( |
297 | + TranslationMessage, make_plurals_sql_fragment) |
298 | +from lp.translations.model.translationtemplateitem import ( |
299 | + TranslationTemplateItem) |
300 | from lp.translations.utilities.translation_common_format import ( |
301 | TranslationMessageData) |
302 | -from canonical.launchpad.webapp.publisher import canonical_url |
303 | -from canonical.librarian.interfaces import ILibrarianClient |
304 | |
305 | from storm.expr import And, Join, LeftJoin, Or, SQL |
306 | from storm.info import ClassAlias |
307 | @@ -520,17 +521,17 @@ |
308 | """See `IPOFile`.""" |
309 | LP_CREDIT_HEADER = u'Launchpad Contributions:' |
310 | SPACE = u' ' |
311 | - msgid = potmsgset.singular_text |
312 | - assert potmsgset.is_translation_credit, ( |
313 | + credits_type = potmsgset.translation_credits_type |
314 | + assert credits_type != TranslationCreditsType.NOT_CREDITS, ( |
315 | "Calling prepareTranslationCredits on a message with " |
316 | - "msgid '%s'." % msgid) |
317 | + "msgid '%s'." % potmsgset.singular_text) |
318 | imported = potmsgset.getImportedTranslationMessage( |
319 | self.potemplate, self.language) |
320 | if imported is None: |
321 | text = None |
322 | else: |
323 | text = imported.translations[0] |
324 | - if msgid in [u'_: EMAIL OF TRANSLATORS\nYour emails', u'Your emails']: |
325 | + if credits_type == TranslationCreditsType.KDE_EMAILS: |
326 | emails = [] |
327 | if text is not None: |
328 | emails.append(text) |
329 | @@ -547,7 +548,7 @@ |
330 | else: |
331 | emails.append(preferred_email.email) |
332 | return u','.join(emails) |
333 | - elif msgid in [u'_: NAME OF TRANSLATORS\nYour names', u'Your names']: |
334 | + elif credits_type == TranslationCreditsType.KDE_NAMES: |
335 | names = [] |
336 | |
337 | if text is not None: |
338 | @@ -561,9 +562,7 @@ |
339 | contributor.displayname |
340 | for contributor in self.contributors]) |
341 | return u','.join(names) |
342 | - elif (msgid in [u'translation-credits', |
343 | - u'translator-credits', |
344 | - u'translator_credits']): |
345 | + elif credits_type == TranslationCreditsType.GNOME: |
346 | if len(list(self.contributors)): |
347 | if text is None: |
348 | text = u'' |
349 | @@ -584,7 +583,7 @@ |
350 | else: |
351 | raise AssertionError( |
352 | "Calling prepareTranslationCredits on a message with " |
353 | - "msgid '%s'." % (msgid)) |
354 | + "unknown credits type '%s'." % credits_type.title) |
355 | |
356 | def canEditTranslations(self, person): |
357 | """See `IPOFile`.""" |
358 | |
359 | === modified file 'lib/lp/translations/model/potmsgset.py' |
360 | --- lib/lp/translations/model/potmsgset.py 2009-08-25 20:15:38 +0000 |
361 | +++ lib/lp/translations/model/potmsgset.py 2009-10-21 10:17:14 +0000 |
362 | @@ -19,13 +19,16 @@ |
363 | from canonical.database.constants import DEFAULT, UTC_NOW |
364 | from canonical.database.sqlbase import cursor, quote, SQLBase, sqlvalues |
365 | from canonical.launchpad import helpers |
366 | +from canonical.launchpad.helpers import shortlist |
367 | from lp.translations.model.translationmessage import ( |
368 | make_plurals_sql_fragment) |
369 | from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities |
370 | +from lp.translations.interfaces.pofile import IPOFileSet |
371 | from lp.translations.interfaces.potmsgset import ( |
372 | BrokenTextError, |
373 | IPOTMsgSet, |
374 | - POTMsgSetInIncompatibleTemplatesError) |
375 | + POTMsgSetInIncompatibleTemplatesError, |
376 | + TranslationCreditsType) |
377 | from lp.translations.interfaces.translationfileformat import ( |
378 | TranslationFileFormat) |
379 | from lp.translations.interfaces.translationimporter import ( |
380 | @@ -35,8 +38,6 @@ |
381 | TranslationConflict, |
382 | TranslationValidationStatus) |
383 | from lp.translations.interfaces.translations import TranslationConstants |
384 | -from canonical.launchpad.helpers import shortlist |
385 | -from lp.translations.interfaces.pofile import IPOFileSet |
386 | from lp.translations.model.pomsgid import POMsgID |
387 | from lp.translations.model.potranslation import POTranslation |
388 | from lp.translations.model.translationmessage import ( |
389 | @@ -47,20 +48,24 @@ |
390 | |
391 | |
392 | # Msgids that indicate translation credit messages, and their |
393 | -# contexts. |
394 | +# contexts and type. |
395 | credit_message_ids = { |
396 | # Regular gettext credits messages. |
397 | - u'translation-credits': None, |
398 | - u'translator-credits': None, |
399 | - u'translator_credits': None, |
400 | + u'translation-credits': (None, TranslationCreditsType.GNOME), |
401 | + u'translator-credits': (None, TranslationCreditsType.GNOME), |
402 | + u'translator_credits': (None, TranslationCreditsType.GNOME), |
403 | |
404 | # KDE credits messages. |
405 | - u'Your emails': u'EMAIL OF TRANSLATORS', |
406 | - u'Your names': u'NAME OF TRANSLATORS', |
407 | + u'Your emails': |
408 | + (u'EMAIL OF TRANSLATORS', TranslationCreditsType.KDE_EMAILS), |
409 | + u'Your names': |
410 | + (u'NAME OF TRANSLATORS', TranslationCreditsType.KDE_NAMES), |
411 | |
412 | # Old KDE credits messages. |
413 | - u'_: EMAIL OF TRANSLATORS\nYour emails': None, |
414 | - u'_: NAME OF TRANSLATORS\nYour names': None, |
415 | + u'_: EMAIL OF TRANSLATORS\nYour emails': |
416 | + (None, TranslationCreditsType.KDE_EMAILS), |
417 | + u'_: NAME OF TRANSLATORS\nYour names': |
418 | + (None, TranslationCreditsType.KDE_NAMES), |
419 | } |
420 | |
421 | |
422 | @@ -999,13 +1004,20 @@ |
423 | @property |
424 | def is_translation_credit(self): |
425 | """See `IPOTMsgSet`.""" |
426 | - # msgid_singular.msgid is pre-joined everywhere where |
427 | - # is_translation_credit is used |
428 | + credit_type = self.translation_credits_type |
429 | + return credit_type != TranslationCreditsType.NOT_CREDITS |
430 | + |
431 | + @property |
432 | + def translation_credits_type(self): |
433 | + """See `IPOTMsgSet`.""" |
434 | if self.msgid_singular.msgid not in credit_message_ids: |
435 | - return False |
436 | + return TranslationCreditsType.NOT_CREDITS |
437 | |
438 | - expected_context = credit_message_ids[self.msgid_singular.msgid] |
439 | - return expected_context is None or (self.context == expected_context) |
440 | + expected_context, credits_type = ( |
441 | + credit_message_ids[self.msgid_singular.msgid]) |
442 | + if expected_context is None or (self.context == expected_context): |
443 | + return credits_type |
444 | + return TranslationCreditsType.NOT_CREDITS |
445 | |
446 | def makeHTMLID(self, suffix=None): |
447 | """See `IPOTMsgSet`.""" |
= Details =
See bug 456498.
This is a simiple refactoring so that the test for strings (msgids) that identify translator credits are not checked in two different places in the code. This makes the code clearer and future additions of translator credit strings would be easier (if they ever happen).
== Implementation notes ==
The property translation_ credit_ type is a string that is a normalized version of the possible msgids for this type. It can be considred to be an enum value but this implementation is simpler and more fitting for this quick refactoring.
== Test ==
bin/test -vvct potmsgset.txt
= Launchpad lint =
Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.
Linting changed files: translations/ doc/potmsgset. txt translations/ interfaces/ potmsgset. py translations/ model/pofile. py translations/ model/potmsgset .py
lib/lp/
lib/lp/
lib/lp/
lib/lp/