1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
PO Import test with a .po file that has a syntax error
======================================================
When we import a .po file with a syntax error, we should notify the user
about that error so they have a chance to fix it.
In this test, we are going to check that we detect and notify the error.
Here are some imports we need to get this test running.
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
>>> from lp.registry.interfaces.person import IPersonSet
>>> from lp.translations.interfaces.translationimportqueue import (
... ITranslationImportQueue)
>>> from lp.translations.model.potemplate import POTemplateSubset
>>> import datetime
>>> import pytz
>>> UTC = pytz.timezone('UTC')
>>> translation_import_queue = getUtility(ITranslationImportQueue)
>>> rosetta_experts = getUtility(ILaunchpadCelebrities).rosetta_experts
We need this for the Librarian to work properly.
>>> import transaction
And also, the DBSchema to change the imports status
>>> from lp.translations.enums import RosettaImportStatus
Login as an admin to be able to do changes to the import queue.
>>> login('carlos@canonical.com')
Here's the person who'll be doing the import.
>>> person_set = getUtility(IPersonSet)
>>> person = person_set.getByName('mark')
Now, is time to create the new potemplate
>>> from lp.registry.model.productrelease import ProductRelease
>>> release = ProductRelease.get(3)
>>> release.productseries.product.name
u'firefox'
>>> series = release.productseries
>>> subset = POTemplateSubset(productseries=series)
>>> potemplate = subset.new(
... name='firefox',
... translation_domain='firefox',
... path='po/firefox.pot',
... owner=person)
We create the POFile object where we are going to attach the .po file.
>>> pofile = potemplate.newPOFile('cy')
Let's import a .po file that misses the '"' char after msgstr. That's a
syntax error.
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-06-03 20:41+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=4; plural=n==1) "
... "? 0 : n==2 ? 1 : (n != 8 || n != 11) ? 2 : 3;\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "foo"
... msgstr blah"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> by_maintainer = False
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, by_maintainer, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
We must approve the entry to be able to import it.
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
The import fails.
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
FAILED
>>> print entry.error_output
Line 12: String is not quoted
And the code composed an email with the notification of the error.
>>> subject
u'Import problem - Welsh (cy) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
<BLANKLINE>
On ..., you uploaded a file with Welsh (cy) translations for firefox in
Mozilla Firefox trunk to Launchpad.
<BLANKLINE>
We were unable to import the file because of errors in its format:
<BLANKLINE>
Line 12: String is not quoted
<BLANKLINE>
If you use gettext, you can check your file for correct formatting with
the 'msgfmt -c' command.
Please fix any errors raised by msgfmt and upload the file again. If you
check the file and you don't find any error in it, please look for an
answer or file a question at https://answers.launchpad.net/rosetta/
<BLANKLINE>
For your convenience, you can get the file you uploaded at:
http://.../firefox-cy.po
<BLANKLINE>
Thank you,
<BLANKLINE>
The Launchpad team
<BLANKLINE>
Encoding errors
---------------
Encoding problems are similarly reported, but with a different
explanatory text.
>>> pofile = potemplate.newPOFile('fy')
>>> pofile_contents = u'''
... msgid ""
... msgstr ""
... "Content-Type: text/plain; charset=ASCII\\n"
... "X-Rosetta-Export-Date: 2009-07-13 00:00+0700\\n"
...
... msgid "\xa9 Yoyodine Industries"
... msgstr ""
... '''.encode('utf-8')
>>> by_maintainer = False
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, by_maintainer, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> transaction.commit()
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
FAILED
An email describes the problem in relatively helpful terms.
>>> subject
u'Import problem - Frisian (fy) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
<BLANKLINE>
On ..., you uploaded a file with Frisian (fy) translations for
firefox in Mozilla Firefox trunk to Launchpad.
<BLANKLINE>
The file could not be imported because of text encoding problems.
This may indicate that the file does not specify the correct
encoding, or that it contains garbled or truncated text data.
<BLANKLINE>
The specific error message was:
<BLANKLINE>
'ascii' codec can't decode byte ... in position ...: ordinal not in
range(128)
<BLANKLINE>
For your convenience, you can find the file you uploaded at: ...
<BLANKLINE>
Thank you,
<BLANKLINE>
The Launchpad team
<BLANKLINE>
The error output field is more terse.
>>> print entry.error_output
'ascii' codec can't decode byte ... in position ...: ordinal not in
range(128)
Invalid numbers of plural forms
-------------------------------
Some uploads declare impossible numbers of plural forms. Those uploads
are rejected.
Non-numeric plural forms
........................
In his rush to be the first Sumerian translator for Firefox, Mark
submits a translation with a nonsensical plurals definition.
>>> pofile = potemplate.newPOFile('sux')
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-06-29 11:44+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=n; plural=0\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "foo"
... msgstr "bar"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, False, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> (subject, message) = pofile.importFromQueue(entry)
The submission is rejected with a syntax error.
>>> print entry.status.name
FAILED
>>> subject
u'Import problem - Sumerian (sux) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
...
<BLANKLINE>
We were unable to import the file because of errors in its format:
<BLANKLINE>
Invalid nplurals declaration in header: 'n' (should be a number).
<BLANKLINE>
...
Not enough forms
................
Mark mistakenly attempts to import a translation with "zero" plural
forms. He receives an email notifying him of a syntax error.
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-06-14 18:33+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=0; plural=0\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "foo"
... msgstr "bar"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, False, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
FAILED
>>> subject
u'Import problem - Sumerian (sux) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
...
<BLANKLINE>
We were unable to import the file because of errors in its format:
<BLANKLINE>
Number of plural forms is impossibly low.
<BLANKLINE>
...
On his next attempt, Mark accidentally types a negative number of plural
forms. The same error is given.
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-06-15 19:04+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=-1; plural=0\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "foo"
... msgstr "bar"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, False, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
FAILED
>>> subject
u'Import problem - Sumerian (sux) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
...
We were unable to import the file because of errors in its format:
<BLANKLINE>
Number of plural forms is impossibly low.
<BLANKLINE>
...
Too many plural forms
---------------------
Next Mark, eclectic polyglot that he is, uploads an Arabic translation.
He mistakenly defines seven instead of six plural forms. That would be
fine but Launchpad only supports up to six forms. He receives a message
about this.
The email points to Launchpad's information about Arabic and shows how
to get that information corrected if need be.
>>> pofile = potemplate.newPOFile('ar')
>>> # PO file with nplurals=7, a value we can't handle.
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-07-01 08:35+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=7; plural=n%%7\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "%%d foo"
... msgid_plural "%%d foos"
... msgstr[0] "bar %%d"
... msgstr[1] "bares %%d"
... msgstr[2] "baris %%d"
... msgstr[3] "baribus %%d"
... msgstr[4] "baros %%d"
... msgstr[5] "barorum %%d"
... msgstr[6] "barim %%d"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, False, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
FAILED
>>> subject
u'Import problem - Arabic (ar) - firefox in Mozilla Firefox trunk'
>>> print message
Hello Mark Shuttleworth,
<BLANKLINE>
On ..., you uploaded a file with Arabic (ar) translations for firefox in
Mozilla Firefox trunk to Launchpad.
<BLANKLINE>
We were unable to import it because it declares more plural forms than
Launchpad can currently handle. The maximum supported is 6.
<BLANKLINE>
Please see if you can get by with fewer plural forms. You can find
Launchpad's default plural-forms information for Arabic (ar) here:
<BLANKLINE>
https://translations.launchpad.net/+languages/ar
<BLANKLINE>
If you believe the information listed there is incorrect, please file a
question here:
<BLANKLINE>
https://answers.launchpad.net/rosetta/+addquestion
<BLANKLINE>
For your convenience, you can get the file you uploaded at:
http://.../firefox-ar.po
<BLANKLINE>
<BLANKLINE>
Thank you,
<BLANKLINE>
The Launchpad team
<BLANKLINE>
Once Mark has checked the language page and corrected the number of
plural forms, the file imports just fine.
>>> # Same PO file as before, but with nplurals=6.
>>> pofile_contents = r'''
... msgid ""
... msgstr ""
... "PO-Revision-Date: 2005-07-01 08:35+0100\n"
... "Last-Translator: Foo <no-priv@canonical.com>\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Plural-Forms: nplurals=6; plural=n%%6\n"
... "X-Rosetta-Export-Date: %s\n"
...
... msgid "%%d foo"
... msgid_plural "%%d foos"
... msgstr[0] "bar %%d"
... msgstr[1] "bares %%d"
... msgstr[2] "baris %%d"
... msgstr[3] "baribus %%d"
... msgstr[4] "baros %%d"
... msgstr[5] "barorum %%d"
... ''' % datetime.datetime.now(UTC).isoformat()
>>> entry = translation_import_queue.addOrUpdateEntry(
... pofile.path, pofile_contents, False, person,
... productseries=series, potemplate=potemplate, pofile=pofile)
>>> transaction.commit()
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts)
>>> (subject, message) = pofile.importFromQueue(entry)
>>> print entry.status.name
IMPORTED
|