Merge lp:~henninge/launchpad/bug-565294-devel into lp:launchpad
- bug-565294-devel
- Merge into devel
Proposed by
Henning Eggers
Status: | Merged |
---|---|
Approved by: | Henning Eggers |
Approved revision: | no longer in the source branch. |
Merged at revision: | not available |
Proposed branch: | lp:~henninge/launchpad/bug-565294-devel |
Merge into: | lp:launchpad |
Diff against target: |
763 lines (+219/-89) 2 files modified
lib/lp/translations/model/pofile.py (+42/-23) lib/lp/translations/tests/test_pofile.py (+177/-66) |
To merge this branch: | bzr merge lp:~henninge/launchpad/bug-565294-devel |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Nelson (community) | code | Approve | |
Review via email: mp+24020@code.launchpad.net |
Commit message
When exporting PO files, use the plural information from the imported file in some cases instead of the information from the language database.
Description of the change
Merging already approved branch into devel instead of production-devel.
https:/
No changes since last approval. ;-)
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/lp/translations/model/pofile.py' | |||
2 | --- lib/lp/translations/model/pofile.py 2010-01-14 16:39:18 +0000 | |||
3 | +++ lib/lp/translations/model/pofile.py 2010-04-26 10:23:30 +0000 | |||
4 | @@ -34,7 +34,6 @@ | |||
5 | 34 | from canonical.launchpad.webapp.interfaces import ( | 34 | from canonical.launchpad.webapp.interfaces import ( |
6 | 35 | DEFAULT_FLAVOR, IStoreSelector, MAIN_STORE, MASTER_FLAVOR) | 35 | DEFAULT_FLAVOR, IStoreSelector, MAIN_STORE, MASTER_FLAVOR) |
7 | 36 | from canonical.launchpad.webapp.publisher import canonical_url | 36 | from canonical.launchpad.webapp.publisher import canonical_url |
8 | 37 | from canonical.librarian.interfaces import ILibrarianClient | ||
9 | 38 | from lp.registry.interfaces.person import validate_public_person | 37 | from lp.registry.interfaces.person import validate_public_person |
10 | 39 | from lp.registry.model.person import Person | 38 | from lp.registry.model.person import Person |
11 | 40 | from lp.translations.utilities.rosettastats import RosettaStats | 39 | from lp.translations.utilities.rosettastats import RosettaStats |
12 | @@ -792,7 +791,6 @@ | |||
13 | 792 | 791 | ||
14 | 793 | # A POT set has "new" suggestions if there is a non current | 792 | # A POT set has "new" suggestions if there is a non current |
15 | 794 | # TranslationMessage newer than the current reviewed one. | 793 | # TranslationMessage newer than the current reviewed one. |
16 | 795 | store = Store.of(self) | ||
17 | 796 | query = ( | 794 | query = ( |
18 | 797 | """POTMsgSet.id IN (SELECT DISTINCT TranslationMessage.potmsgset | 795 | """POTMsgSet.id IN (SELECT DISTINCT TranslationMessage.potmsgset |
19 | 798 | FROM TranslationMessage, TranslationTemplateItem, POTMsgSet | 796 | FROM TranslationMessage, TranslationTemplateItem, POTMsgSet |
20 | @@ -1026,10 +1024,6 @@ | |||
21 | 1026 | entry_to_import = removeSecurityProxy(entry_to_import) | 1024 | entry_to_import = removeSecurityProxy(entry_to_import) |
22 | 1027 | 1025 | ||
23 | 1028 | translation_importer = getUtility(ITranslationImporter) | 1026 | translation_importer = getUtility(ITranslationImporter) |
24 | 1029 | librarian_client = getUtility(ILibrarianClient) | ||
25 | 1030 | |||
26 | 1031 | import_file = librarian_client.getFileByAlias( | ||
27 | 1032 | entry_to_import.content.id) | ||
28 | 1033 | 1027 | ||
29 | 1034 | # While importing a file, there are two kinds of errors: | 1028 | # While importing a file, there are two kinds of errors: |
30 | 1035 | # | 1029 | # |
31 | @@ -1125,7 +1119,6 @@ | |||
32 | 1125 | # There were some errors with translations. | 1119 | # There were some errors with translations. |
33 | 1126 | errorsdetails = '' | 1120 | errorsdetails = '' |
34 | 1127 | for error in errors: | 1121 | for error in errors: |
35 | 1128 | pofile = error['pofile'] | ||
36 | 1129 | potmsgset = error['potmsgset'] | 1122 | potmsgset = error['potmsgset'] |
37 | 1130 | pomessage = error['pomessage'] | 1123 | pomessage = error['pomessage'] |
38 | 1131 | error_message = error['error-message'] | 1124 | error_message = error['error-message'] |
39 | @@ -1706,6 +1699,47 @@ | |||
40 | 1706 | 1699 | ||
41 | 1707 | return self._pofile.language.code | 1700 | return self._pofile.language.code |
42 | 1708 | 1701 | ||
43 | 1702 | def _isWesternPluralForm(self, number, expression): | ||
44 | 1703 | # Western style is nplurals=2;plural=n!=1. | ||
45 | 1704 | if number != 2: | ||
46 | 1705 | return False | ||
47 | 1706 | if expression is None: | ||
48 | 1707 | return False | ||
49 | 1708 | # Normalize: Remove spaces. | ||
50 | 1709 | expression = expression.replace(' ', '') | ||
51 | 1710 | # Normalize: Remove enclosing brackets. | ||
52 | 1711 | expression = expression.strip('()') | ||
53 | 1712 | return expression in ('n!=1', '1!=n', 'n>1', '1<n') | ||
54 | 1713 | |||
55 | 1714 | def _updateHeaderPluralInfo(self, header): | ||
56 | 1715 | header_nplurals = header.number_plural_forms | ||
57 | 1716 | database_nplurals = self._pofile.language.pluralforms | ||
58 | 1717 | # These checks are here to catch cases where the plural information | ||
59 | 1718 | # from the header might be more acurate than what we have in the | ||
60 | 1719 | # database. This is usually the case when the number of plural forms | ||
61 | 1720 | # has grown but not if it's the standard western form. | ||
62 | 1721 | # See bug 565294 | ||
63 | 1722 | if header_nplurals is not None and database_nplurals is not None: | ||
64 | 1723 | if header_nplurals > database_nplurals: | ||
65 | 1724 | is_western = self._isWesternPluralForm( | ||
66 | 1725 | header_nplurals, header.plural_form_expression) | ||
67 | 1726 | if not is_western: | ||
68 | 1727 | # Use existing information from the header. | ||
69 | 1728 | return | ||
70 | 1729 | if database_nplurals is None: | ||
71 | 1730 | # In all other cases we never use the plural info from the header. | ||
72 | 1731 | header.number_plural_forms = None | ||
73 | 1732 | header.plural_form_expression = None | ||
74 | 1733 | else: | ||
75 | 1734 | # We have pluralforms information for this language so we | ||
76 | 1735 | # update the header to be sure that we use the language | ||
77 | 1736 | # information from our database instead of using the one | ||
78 | 1737 | # that we got from upstream. We check this information so | ||
79 | 1738 | # we are sure it's valid. | ||
80 | 1739 | header.number_plural_forms = self._pofile.language.pluralforms | ||
81 | 1740 | header.plural_form_expression = ( | ||
82 | 1741 | self._pofile.language.pluralexpression) | ||
83 | 1742 | |||
84 | 1709 | @cachedproperty | 1743 | @cachedproperty |
85 | 1710 | def header(self): | 1744 | def header(self): |
86 | 1711 | """See `ITranslationFileData`.""" | 1745 | """See `ITranslationFileData`.""" |
87 | @@ -1713,28 +1747,13 @@ | |||
88 | 1713 | translation_header = self._pofile.getHeader() | 1747 | translation_header = self._pofile.getHeader() |
89 | 1714 | # Update default fields based on its values in the template header. | 1748 | # Update default fields based on its values in the template header. |
90 | 1715 | translation_header.updateFromTemplateHeader(template_header) | 1749 | translation_header.updateFromTemplateHeader(template_header) |
91 | 1716 | date_reviewed = None | ||
92 | 1717 | translation_header.translation_revision_date = ( | 1750 | translation_header.translation_revision_date = ( |
93 | 1718 | self._pofile.date_changed) | 1751 | self._pofile.date_changed) |
94 | 1719 | 1752 | ||
95 | 1720 | translation_header.comment = self._pofile.topcomment | 1753 | translation_header.comment = self._pofile.topcomment |
96 | 1721 | 1754 | ||
97 | 1722 | if self._pofile.potemplate.hasPluralMessage(): | 1755 | if self._pofile.potemplate.hasPluralMessage(): |
113 | 1723 | number_plural_forms = None | 1756 | self._updateHeaderPluralInfo(translation_header) |
99 | 1724 | plural_form_expression = None | ||
100 | 1725 | if self._pofile.language.pluralforms is not None: | ||
101 | 1726 | # We have pluralforms information for this language so we | ||
102 | 1727 | # update the header to be sure that we use the language | ||
103 | 1728 | # information from our database instead of use the one | ||
104 | 1729 | # that we got from upstream. We check this information so | ||
105 | 1730 | # we are sure it's valid. | ||
106 | 1731 | number_plural_forms = self._pofile.language.pluralforms | ||
107 | 1732 | plural_form_expression = ( | ||
108 | 1733 | self._pofile.language.pluralexpression) | ||
109 | 1734 | |||
110 | 1735 | translation_header.number_plural_forms = number_plural_forms | ||
111 | 1736 | translation_header.plural_form_expression = plural_form_expression | ||
112 | 1737 | |||
114 | 1738 | if (self._pofile.lasttranslator is not None): | 1757 | if (self._pofile.lasttranslator is not None): |
115 | 1739 | email = self._pofile.lasttranslator.safe_email_or_blank | 1758 | email = self._pofile.lasttranslator.safe_email_or_blank |
116 | 1740 | if not email: | 1759 | if not email: |
117 | 1741 | 1760 | ||
118 | === modified file 'lib/lp/translations/tests/test_pofile.py' | |||
119 | --- lib/lp/translations/tests/test_pofile.py 2010-01-12 21:29:03 +0000 | |||
120 | +++ lib/lp/translations/tests/test_pofile.py 2010-04-26 10:23:30 +0000 | |||
121 | @@ -7,7 +7,8 @@ | |||
122 | 7 | 7 | ||
123 | 8 | from datetime import datetime, timedelta | 8 | from datetime import datetime, timedelta |
124 | 9 | import pytz | 9 | import pytz |
126 | 10 | import unittest | 10 | from textwrap import dedent |
127 | 11 | from unittest import TestLoader | ||
128 | 11 | 12 | ||
129 | 12 | from zope.component import getAdapter, getUtility | 13 | from zope.component import getAdapter, getUtility |
130 | 13 | from zope.security.proxy import removeSecurityProxy | 14 | from zope.security.proxy import removeSecurityProxy |
131 | @@ -93,7 +94,7 @@ | |||
132 | 93 | self.assertEquals(found_potmsgsets, [plural_potmsgset]) | 94 | self.assertEquals(found_potmsgsets, [plural_potmsgset]) |
133 | 94 | 95 | ||
134 | 95 | # Search translations as well. | 96 | # Search translations as well. |
136 | 96 | translation = self.factory.makeTranslationMessage( | 97 | self.factory.makeTranslationMessage( |
137 | 97 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 98 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
138 | 98 | translations=[u"One translation message"]) | 99 | translations=[u"One translation message"]) |
139 | 99 | found_potmsgsets = list( | 100 | found_potmsgsets = list( |
140 | @@ -101,7 +102,7 @@ | |||
141 | 101 | self.assertEquals(found_potmsgsets, [potmsgset]) | 102 | self.assertEquals(found_potmsgsets, [potmsgset]) |
142 | 102 | 103 | ||
143 | 103 | # Search matches all plural forms. | 104 | # Search matches all plural forms. |
145 | 104 | plural_translation = self.factory.makeTranslationMessage( | 105 | self.factory.makeTranslationMessage( |
146 | 105 | pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset, | 106 | pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset, |
147 | 106 | translations=[u"One translation message", | 107 | translations=[u"One translation message", |
148 | 107 | u"Plural translation message", | 108 | u"Plural translation message", |
149 | @@ -153,7 +154,7 @@ | |||
150 | 153 | # If somebody else provides a translation, it's not added to the | 154 | # If somebody else provides a translation, it's not added to the |
151 | 154 | # list of submitter's translations. | 155 | # list of submitter's translations. |
152 | 155 | someone_else = self.factory.makePerson() | 156 | someone_else = self.factory.makePerson() |
154 | 156 | other_translation = self.factory.makeTranslationMessage( | 157 | self.factory.makeTranslationMessage( |
155 | 157 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 158 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
156 | 158 | translations=[u"Another translation"], | 159 | translations=[u"Another translation"], |
157 | 159 | translator=someone_else) | 160 | translator=someone_else) |
158 | @@ -166,7 +167,7 @@ | |||
159 | 166 | # to the list of submitter's translations for *former* POFile. | 167 | # to the list of submitter's translations for *former* POFile. |
160 | 167 | self.devel_sr_latin_pofile = self.factory.makePOFile( | 168 | self.devel_sr_latin_pofile = self.factory.makePOFile( |
161 | 168 | 'sr', variant=u'latin', potemplate=self.devel_potemplate) | 169 | 'sr', variant=u'latin', potemplate=self.devel_potemplate) |
163 | 169 | latin_translation = self.factory.makeTranslationMessage( | 170 | self.factory.makeTranslationMessage( |
164 | 170 | pofile=self.devel_sr_latin_pofile, potmsgset=potmsgset, | 171 | pofile=self.devel_sr_latin_pofile, potmsgset=potmsgset, |
165 | 171 | translations=[u"Yet another translation"], | 172 | translations=[u"Yet another translation"], |
166 | 172 | translator=submitter) | 173 | translator=submitter) |
167 | @@ -194,7 +195,7 @@ | |||
168 | 194 | self.assertEquals(found_translations, []) | 195 | self.assertEquals(found_translations, []) |
169 | 195 | 196 | ||
170 | 196 | # When a diverged translation is added, the potmsgset is returned. | 197 | # When a diverged translation is added, the potmsgset is returned. |
172 | 197 | translation = self.factory.makeTranslationMessage( | 198 | self.factory.makeTranslationMessage( |
173 | 198 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 199 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
174 | 199 | translations=[u"Translation"]) | 200 | translations=[u"Translation"]) |
175 | 200 | found_translations = list( | 201 | found_translations = list( |
176 | @@ -202,7 +203,7 @@ | |||
177 | 202 | self.assertEquals(found_translations, [self.potmsgset]) | 203 | self.assertEquals(found_translations, [self.potmsgset]) |
178 | 203 | 204 | ||
179 | 204 | # If diverged translation is empty, POTMsgSet is not listed. | 205 | # If diverged translation is empty, POTMsgSet is not listed. |
181 | 205 | translation = self.factory.makeTranslationMessage( | 206 | self.factory.makeTranslationMessage( |
182 | 206 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 207 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
183 | 207 | translations=[u""]) | 208 | translations=[u""]) |
184 | 208 | found_translations = list( | 209 | found_translations = list( |
185 | @@ -214,7 +215,7 @@ | |||
186 | 214 | # translation for the POTMsgSet as well. | 215 | # translation for the POTMsgSet as well. |
187 | 215 | 216 | ||
188 | 216 | # We create a shared translation first. | 217 | # We create a shared translation first. |
190 | 217 | shared_translation = self.factory.makeSharedTranslationMessage( | 218 | self.factory.makeSharedTranslationMessage( |
191 | 218 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 219 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
192 | 219 | translations=[u"Shared translation"]) | 220 | translations=[u"Shared translation"]) |
193 | 220 | 221 | ||
194 | @@ -224,7 +225,7 @@ | |||
195 | 224 | self.assertEquals(found_translations, [self.potmsgset]) | 225 | self.assertEquals(found_translations, [self.potmsgset]) |
196 | 225 | 226 | ||
197 | 226 | # When an empty diverged translation is added, nothing is listed. | 227 | # When an empty diverged translation is added, nothing is listed. |
199 | 227 | translation = self.factory.makeTranslationMessage( | 228 | self.factory.makeTranslationMessage( |
200 | 228 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 229 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
201 | 229 | translations=[u""]) | 230 | translations=[u""]) |
202 | 230 | found_translations = list( | 231 | found_translations = list( |
203 | @@ -232,7 +233,7 @@ | |||
204 | 232 | self.assertEquals(found_translations, []) | 233 | self.assertEquals(found_translations, []) |
205 | 233 | 234 | ||
206 | 234 | # If diverged translation is non-empty, POTMsgSet is listed. | 235 | # If diverged translation is non-empty, POTMsgSet is listed. |
208 | 235 | translation = self.factory.makeTranslationMessage( | 236 | self.factory.makeTranslationMessage( |
209 | 236 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 237 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
210 | 237 | translations=[u"Translation"]) | 238 | translations=[u"Translation"]) |
211 | 238 | found_translations = list( | 239 | found_translations = list( |
212 | @@ -244,7 +245,7 @@ | |||
213 | 244 | # empty shared translation for the POTMsgSet as well. | 245 | # empty shared translation for the POTMsgSet as well. |
214 | 245 | 246 | ||
215 | 246 | # We create an empty shared translation first. | 247 | # We create an empty shared translation first. |
217 | 247 | shared_translation = self.factory.makeSharedTranslationMessage( | 248 | self.factory.makeSharedTranslationMessage( |
218 | 248 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 249 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
219 | 249 | translations=[u""]) | 250 | translations=[u""]) |
220 | 250 | 251 | ||
221 | @@ -255,7 +256,7 @@ | |||
222 | 255 | self.assertEquals(found_translations, []) | 256 | self.assertEquals(found_translations, []) |
223 | 256 | 257 | ||
224 | 257 | # When an empty diverged translation is added, nothing is listed. | 258 | # When an empty diverged translation is added, nothing is listed. |
226 | 258 | translation = self.factory.makeTranslationMessage( | 259 | self.factory.makeTranslationMessage( |
227 | 259 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 260 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
228 | 260 | translations=[u""]) | 261 | translations=[u""]) |
229 | 261 | found_translations = list( | 262 | found_translations = list( |
230 | @@ -263,7 +264,7 @@ | |||
231 | 263 | self.assertEquals(found_translations, []) | 264 | self.assertEquals(found_translations, []) |
232 | 264 | 265 | ||
233 | 265 | # If diverged translation is non-empty, POTMsgSet is listed. | 266 | # If diverged translation is non-empty, POTMsgSet is listed. |
235 | 266 | translation = self.factory.makeTranslationMessage( | 267 | self.factory.makeTranslationMessage( |
236 | 267 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 268 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
237 | 268 | translations=[u"Translation"]) | 269 | translations=[u"Translation"]) |
238 | 269 | found_translations = list( | 270 | found_translations = list( |
239 | @@ -275,7 +276,7 @@ | |||
240 | 275 | # translated message. | 276 | # translated message. |
241 | 276 | 277 | ||
242 | 277 | # Add a diverged translation on the included POTMsgSet... | 278 | # Add a diverged translation on the included POTMsgSet... |
244 | 278 | translation = self.factory.makeTranslationMessage( | 279 | self.factory.makeTranslationMessage( |
245 | 279 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 280 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
246 | 280 | translations=[u"Diverged translation"]) | 281 | translations=[u"Diverged translation"]) |
247 | 281 | 282 | ||
248 | @@ -284,7 +285,7 @@ | |||
249 | 284 | u"Translated text") | 285 | u"Translated text") |
250 | 285 | potmsgset.setSequence(self.devel_potemplate, 2) | 286 | potmsgset.setSequence(self.devel_potemplate, 2) |
251 | 286 | 287 | ||
253 | 287 | shared_translation = self.factory.makeSharedTranslationMessage( | 288 | self.factory.makeSharedTranslationMessage( |
254 | 288 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 289 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
255 | 289 | translations=[u"Shared translation"]) | 290 | translations=[u"Shared translation"]) |
256 | 290 | 291 | ||
257 | @@ -303,7 +304,7 @@ | |||
258 | 303 | self.assertEquals(found_translations, [self.potmsgset]) | 304 | self.assertEquals(found_translations, [self.potmsgset]) |
259 | 304 | 305 | ||
260 | 305 | # When a diverged translation is added, the potmsgset is returned. | 306 | # When a diverged translation is added, the potmsgset is returned. |
262 | 306 | translation = self.factory.makeTranslationMessage( | 307 | self.factory.makeTranslationMessage( |
263 | 307 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 308 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
264 | 308 | translations=[u"Translation"]) | 309 | translations=[u"Translation"]) |
265 | 309 | found_translations = list( | 310 | found_translations = list( |
266 | @@ -311,7 +312,7 @@ | |||
267 | 311 | self.assertEquals(found_translations, []) | 312 | self.assertEquals(found_translations, []) |
268 | 312 | 313 | ||
269 | 313 | # If diverged translation is empty, POTMsgSet is not listed. | 314 | # If diverged translation is empty, POTMsgSet is not listed. |
271 | 314 | translation = self.factory.makeTranslationMessage( | 315 | self.factory.makeTranslationMessage( |
272 | 315 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 316 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
273 | 316 | translations=[u""]) | 317 | translations=[u""]) |
274 | 317 | found_translations = list( | 318 | found_translations = list( |
275 | @@ -323,7 +324,7 @@ | |||
276 | 323 | # translation for the POTMsgSet as well. | 324 | # translation for the POTMsgSet as well. |
277 | 324 | 325 | ||
278 | 325 | # We create a shared translation first. | 326 | # We create a shared translation first. |
280 | 326 | shared_translation = self.factory.makeSharedTranslationMessage( | 327 | self.factory.makeSharedTranslationMessage( |
281 | 327 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 328 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
282 | 328 | translations=[u"Shared translation"]) | 329 | translations=[u"Shared translation"]) |
283 | 329 | 330 | ||
284 | @@ -333,7 +334,7 @@ | |||
285 | 333 | self.assertEquals(found_translations, []) | 334 | self.assertEquals(found_translations, []) |
286 | 334 | 335 | ||
287 | 335 | # When an empty diverged translation is added, nothing is listed. | 336 | # When an empty diverged translation is added, nothing is listed. |
289 | 336 | translation = self.factory.makeTranslationMessage( | 337 | self.factory.makeTranslationMessage( |
290 | 337 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 338 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
291 | 338 | translations=[u""]) | 339 | translations=[u""]) |
292 | 339 | found_translations = list( | 340 | found_translations = list( |
293 | @@ -341,7 +342,7 @@ | |||
294 | 341 | self.assertEquals(found_translations, [self.potmsgset]) | 342 | self.assertEquals(found_translations, [self.potmsgset]) |
295 | 342 | 343 | ||
296 | 343 | # If diverged translation is non-empty, POTMsgSet is listed. | 344 | # If diverged translation is non-empty, POTMsgSet is listed. |
298 | 344 | translation = self.factory.makeTranslationMessage( | 345 | self.factory.makeTranslationMessage( |
299 | 345 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 346 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
300 | 346 | translations=[u"Translation"]) | 347 | translations=[u"Translation"]) |
301 | 347 | found_translations = list( | 348 | found_translations = list( |
302 | @@ -353,7 +354,7 @@ | |||
303 | 353 | # empty shared translation for the POTMsgSet as well. | 354 | # empty shared translation for the POTMsgSet as well. |
304 | 354 | 355 | ||
305 | 355 | # We create an empty shared translation first. | 356 | # We create an empty shared translation first. |
307 | 356 | shared_translation = self.factory.makeSharedTranslationMessage( | 357 | self.factory.makeSharedTranslationMessage( |
308 | 357 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 358 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
309 | 358 | translations=[u""]) | 359 | translations=[u""]) |
310 | 359 | 360 | ||
311 | @@ -364,7 +365,7 @@ | |||
312 | 364 | self.assertEquals(found_translations, [self.potmsgset]) | 365 | self.assertEquals(found_translations, [self.potmsgset]) |
313 | 365 | 366 | ||
314 | 366 | # When an empty diverged translation is added, nothing is listed. | 367 | # When an empty diverged translation is added, nothing is listed. |
316 | 367 | translation = self.factory.makeTranslationMessage( | 368 | self.factory.makeTranslationMessage( |
317 | 368 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 369 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
318 | 369 | translations=[u""]) | 370 | translations=[u""]) |
319 | 370 | found_translations = list( | 371 | found_translations = list( |
320 | @@ -372,7 +373,7 @@ | |||
321 | 372 | self.assertEquals(found_translations, [self.potmsgset]) | 373 | self.assertEquals(found_translations, [self.potmsgset]) |
322 | 373 | 374 | ||
323 | 374 | # If diverged translation is non-empty, POTMsgSet is listed. | 375 | # If diverged translation is non-empty, POTMsgSet is listed. |
325 | 375 | translation = self.factory.makeTranslationMessage( | 376 | self.factory.makeTranslationMessage( |
326 | 376 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 377 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
327 | 377 | translations=[u"Translation"]) | 378 | translations=[u"Translation"]) |
328 | 378 | found_translations = list( | 379 | found_translations = list( |
329 | @@ -384,7 +385,7 @@ | |||
330 | 384 | # untranslated message. | 385 | # untranslated message. |
331 | 385 | 386 | ||
332 | 386 | # Add an empty translation to the included POTMsgSet... | 387 | # Add an empty translation to the included POTMsgSet... |
334 | 387 | translation = self.factory.makeTranslationMessage( | 388 | self.factory.makeTranslationMessage( |
335 | 388 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 389 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
336 | 389 | translations=[u""]) | 390 | translations=[u""]) |
337 | 390 | 391 | ||
338 | @@ -478,14 +479,14 @@ | |||
339 | 478 | 479 | ||
340 | 479 | # A POTMsgSet has a shared, current translation created 5 days ago. | 480 | # A POTMsgSet has a shared, current translation created 5 days ago. |
341 | 480 | date_created = datetime.now(pytz.UTC)-timedelta(5) | 481 | date_created = datetime.now(pytz.UTC)-timedelta(5) |
343 | 481 | translation = self.factory.makeSharedTranslationMessage( | 482 | self.factory.makeSharedTranslationMessage( |
344 | 482 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 483 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
345 | 483 | translations=[u"Shared translation"], date_updated=date_created) | 484 | translations=[u"Shared translation"], date_updated=date_created) |
346 | 484 | 485 | ||
347 | 485 | # And we also have a diverged translation created a day after shared | 486 | # And we also have a diverged translation created a day after shared |
348 | 486 | # current translation. | 487 | # current translation. |
349 | 487 | diverged_date = date_created + timedelta(1) | 488 | diverged_date = date_created + timedelta(1) |
351 | 488 | translation = self.factory.makeTranslationMessage( | 489 | self.factory.makeTranslationMessage( |
352 | 489 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 490 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
353 | 490 | translations=[u"Old translation"], date_updated=diverged_date) | 491 | translations=[u"Old translation"], date_updated=diverged_date) |
354 | 491 | 492 | ||
355 | @@ -536,7 +537,7 @@ | |||
356 | 536 | # Test that multiple unreviewed POTMsgSets are returned. | 537 | # Test that multiple unreviewed POTMsgSets are returned. |
357 | 537 | 538 | ||
358 | 538 | # One POTMsgSet has no translations, but only a suggestion. | 539 | # One POTMsgSet has no translations, but only a suggestion. |
360 | 539 | translation = self.factory.makeTranslationMessage( | 540 | self.factory.makeTranslationMessage( |
361 | 540 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 541 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
362 | 541 | translations=[u"New suggestion"], suggestion=True) | 542 | translations=[u"New suggestion"], suggestion=True) |
363 | 542 | 543 | ||
364 | @@ -545,11 +546,11 @@ | |||
365 | 545 | u"Translated text") | 546 | u"Translated text") |
366 | 546 | potmsgset.setSequence(self.devel_potemplate, 2) | 547 | potmsgset.setSequence(self.devel_potemplate, 2) |
367 | 547 | date_created = datetime.now(pytz.UTC) - timedelta(5) | 548 | date_created = datetime.now(pytz.UTC) - timedelta(5) |
369 | 548 | translation = self.factory.makeTranslationMessage( | 549 | self.factory.makeTranslationMessage( |
370 | 549 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 550 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
371 | 550 | translations=[u"Translation"], date_updated=date_created) | 551 | translations=[u"Translation"], date_updated=date_created) |
372 | 551 | suggestion_date = date_created + timedelta(1) | 552 | suggestion_date = date_created + timedelta(1) |
374 | 552 | translation = self.factory.makeTranslationMessage( | 553 | self.factory.makeTranslationMessage( |
375 | 553 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 554 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
376 | 554 | translations=[u"New suggestion"], suggestion=True, | 555 | translations=[u"New suggestion"], suggestion=True, |
377 | 555 | date_updated=suggestion_date) | 556 | date_updated=suggestion_date) |
378 | @@ -562,12 +563,12 @@ | |||
379 | 562 | def test_getPOTMsgSetWithNewSuggestions_distinct(self): | 563 | def test_getPOTMsgSetWithNewSuggestions_distinct(self): |
380 | 563 | # Provide two suggestions on a single message and make sure | 564 | # Provide two suggestions on a single message and make sure |
381 | 564 | # a POTMsgSet is returned only once. | 565 | # a POTMsgSet is returned only once. |
383 | 565 | translation1 = self.factory.makeSharedTranslationMessage( | 566 | self.factory.makeSharedTranslationMessage( |
384 | 566 | pofile=self.devel_sr_pofile, | 567 | pofile=self.devel_sr_pofile, |
385 | 567 | potmsgset=self.potmsgset, | 568 | potmsgset=self.potmsgset, |
386 | 568 | translations=["A suggestion"], | 569 | translations=["A suggestion"], |
387 | 569 | suggestion=True) | 570 | suggestion=True) |
389 | 570 | translation2 = self.factory.makeSharedTranslationMessage( | 571 | self.factory.makeSharedTranslationMessage( |
390 | 571 | pofile=self.devel_sr_pofile, | 572 | pofile=self.devel_sr_pofile, |
391 | 572 | potmsgset=self.potmsgset, | 573 | potmsgset=self.potmsgset, |
392 | 573 | translations=["Another suggestion"], | 574 | translations=["Another suggestion"], |
393 | @@ -646,7 +647,6 @@ | |||
394 | 646 | 647 | ||
395 | 647 | # But adding a diverged current and imported translation means | 648 | # But adding a diverged current and imported translation means |
396 | 648 | # that it's not changed anymore. | 649 | # that it's not changed anymore. |
397 | 649 | old_translation = translation | ||
398 | 650 | translation = self.factory.makeTranslationMessage( | 650 | translation = self.factory.makeTranslationMessage( |
399 | 651 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, | 651 | pofile=self.devel_sr_pofile, potmsgset=self.potmsgset, |
400 | 652 | translations=[u"Diverged imported"], is_imported=True, | 652 | translations=[u"Diverged imported"], is_imported=True, |
401 | @@ -753,42 +753,42 @@ | |||
402 | 753 | # Second POTMsgSet is untranslated, but with a suggestion. | 753 | # Second POTMsgSet is untranslated, but with a suggestion. |
403 | 754 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) | 754 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) |
404 | 755 | potmsgset.setSequence(self.devel_potemplate, 2) | 755 | potmsgset.setSequence(self.devel_potemplate, 2) |
406 | 756 | translation = self.factory.makeTranslationMessage( | 756 | self.factory.makeTranslationMessage( |
407 | 757 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 757 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
408 | 758 | translations=[u"Unreviewed suggestion"], suggestion=True) | 758 | translations=[u"Unreviewed suggestion"], suggestion=True) |
409 | 759 | 759 | ||
410 | 760 | # Third POTMsgSet is translated, and with a suggestion. | 760 | # Third POTMsgSet is translated, and with a suggestion. |
411 | 761 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) | 761 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) |
412 | 762 | potmsgset.setSequence(self.devel_potemplate, 3) | 762 | potmsgset.setSequence(self.devel_potemplate, 3) |
414 | 763 | translation = self.factory.makeTranslationMessage( | 763 | self.factory.makeTranslationMessage( |
415 | 764 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 764 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
416 | 765 | translations=[u"Translation"], suggestion=False, | 765 | translations=[u"Translation"], suggestion=False, |
417 | 766 | date_updated=datetime.now(pytz.UTC)-timedelta(1)) | 766 | date_updated=datetime.now(pytz.UTC)-timedelta(1)) |
419 | 767 | translation = self.factory.makeTranslationMessage( | 767 | self.factory.makeTranslationMessage( |
420 | 768 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 768 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
421 | 769 | translations=[u"Another suggestion"], suggestion=True) | 769 | translations=[u"Another suggestion"], suggestion=True) |
422 | 770 | 770 | ||
423 | 771 | # Fourth POTMsgSet is translated in import. | 771 | # Fourth POTMsgSet is translated in import. |
424 | 772 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) | 772 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) |
425 | 773 | potmsgset.setSequence(self.devel_potemplate, 4) | 773 | potmsgset.setSequence(self.devel_potemplate, 4) |
427 | 774 | translation = self.factory.makeTranslationMessage( | 774 | self.factory.makeTranslationMessage( |
428 | 775 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 775 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
429 | 776 | translations=[u"Imported translation"], is_imported=True) | 776 | translations=[u"Imported translation"], is_imported=True) |
430 | 777 | 777 | ||
431 | 778 | # Fifth POTMsgSet is translated in import, but changed in LP. | 778 | # Fifth POTMsgSet is translated in import, but changed in LP. |
432 | 779 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) | 779 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) |
433 | 780 | potmsgset.setSequence(self.devel_potemplate, 5) | 780 | potmsgset.setSequence(self.devel_potemplate, 5) |
435 | 781 | translation = self.factory.makeTranslationMessage( | 781 | self.factory.makeTranslationMessage( |
436 | 782 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 782 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
437 | 783 | translations=[u"Imported translation"], is_imported=True) | 783 | translations=[u"Imported translation"], is_imported=True) |
439 | 784 | translation = self.factory.makeTranslationMessage( | 784 | self.factory.makeTranslationMessage( |
440 | 785 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 785 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
441 | 786 | translations=[u"LP translation"], is_imported=False) | 786 | translations=[u"LP translation"], is_imported=False) |
442 | 787 | 787 | ||
443 | 788 | # Sixth POTMsgSet is translated in LP only. | 788 | # Sixth POTMsgSet is translated in LP only. |
444 | 789 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) | 789 | potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate) |
445 | 790 | potmsgset.setSequence(self.devel_potemplate, 6) | 790 | potmsgset.setSequence(self.devel_potemplate, 6) |
447 | 791 | translation = self.factory.makeTranslationMessage( | 791 | self.factory.makeTranslationMessage( |
448 | 792 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, | 792 | pofile=self.devel_sr_pofile, potmsgset=potmsgset, |
449 | 793 | translations=[u"New translation"], is_imported=False) | 793 | translations=[u"New translation"], is_imported=False) |
450 | 794 | 794 | ||
451 | @@ -810,7 +810,7 @@ | |||
452 | 810 | def test_TranslationFileData_adapter(self): | 810 | def test_TranslationFileData_adapter(self): |
453 | 811 | # Test that exporting works correctly with shared and diverged | 811 | # Test that exporting works correctly with shared and diverged |
454 | 812 | # messages. | 812 | # messages. |
456 | 813 | shared_translation = self.factory.makeSharedTranslationMessage( | 813 | self.factory.makeSharedTranslationMessage( |
457 | 814 | pofile=self.devel_sr_pofile, | 814 | pofile=self.devel_sr_pofile, |
458 | 815 | potmsgset=self.potmsgset, | 815 | potmsgset=self.potmsgset, |
459 | 816 | translations=["Shared translation"]) | 816 | translations=["Shared translation"]) |
460 | @@ -827,7 +827,7 @@ | |||
461 | 827 | "Shared translation")]) | 827 | "Shared translation")]) |
462 | 828 | 828 | ||
463 | 829 | # When we add a diverged translation, only that is exported. | 829 | # When we add a diverged translation, only that is exported. |
465 | 830 | diverged_translation = self.factory.makeTranslationMessage( | 830 | self.factory.makeTranslationMessage( |
466 | 831 | pofile=self.devel_sr_pofile, | 831 | pofile=self.devel_sr_pofile, |
467 | 832 | potmsgset=self.potmsgset, | 832 | potmsgset=self.potmsgset, |
468 | 833 | translations=["Diverged translation"], | 833 | translations=["Diverged translation"], |
469 | @@ -887,7 +887,7 @@ | |||
470 | 887 | productseries=self.foo_stable, name="template-2") | 887 | productseries=self.foo_stable, name="template-2") |
471 | 888 | 888 | ||
472 | 889 | self.assertEqual(None, potemplate_devel_1.getPOFileByLang('eo')) | 889 | self.assertEqual(None, potemplate_devel_1.getPOFileByLang('eo')) |
474 | 890 | pofile_devel = potemplate_devel_1.newPOFile('eo') | 890 | potemplate_devel_1.newPOFile('eo') |
475 | 891 | self.assertEqual(None, potemplate_stable_2.getPOFileByLang('eo')) | 891 | self.assertEqual(None, potemplate_stable_2.getPOFileByLang('eo')) |
476 | 892 | 892 | ||
477 | 893 | def test_potemplate_creation(self): | 893 | def test_potemplate_creation(self): |
478 | @@ -895,14 +895,14 @@ | |||
479 | 895 | # all shared potemplates. | 895 | # all shared potemplates. |
480 | 896 | foo_other = self.factory.makeProductSeries( | 896 | foo_other = self.factory.makeProductSeries( |
481 | 897 | name='other', product=self.foo) | 897 | name='other', product=self.foo) |
483 | 898 | other_potemplate = self.factory.makePOTemplate( | 898 | self.factory.makePOTemplate( |
484 | 899 | productseries=foo_other, name="messages") | 899 | productseries=foo_other, name="messages") |
485 | 900 | devel_potemplate = self.factory.makePOTemplate( | 900 | devel_potemplate = self.factory.makePOTemplate( |
486 | 901 | productseries=self.foo_devel, name="messages") | 901 | productseries=self.foo_devel, name="messages") |
487 | 902 | # These will automatically be shared across all sharing templates. | 902 | # These will automatically be shared across all sharing templates. |
488 | 903 | # They will also be created in the 'other' series. | 903 | # They will also be created in the 'other' series. |
491 | 904 | pofile_devel_eo = devel_potemplate.newPOFile('eo') | 904 | devel_potemplate.newPOFile('eo') |
492 | 905 | pofile_devel_de = devel_potemplate.newPOFile('de') | 905 | devel_potemplate.newPOFile('de') |
493 | 906 | 906 | ||
494 | 907 | stable_potemplate = self.factory.makePOTemplate( | 907 | stable_potemplate = self.factory.makePOTemplate( |
495 | 908 | productseries=self.foo_stable, name="messages") | 908 | productseries=self.foo_stable, name="messages") |
496 | @@ -1015,11 +1015,11 @@ | |||
497 | 1015 | def test_getPOTMsgSetTranslated_ordering(self): | 1015 | def test_getPOTMsgSetTranslated_ordering(self): |
498 | 1016 | # Translate both POTMsgSets in devel_sr_pofile, so | 1016 | # Translate both POTMsgSets in devel_sr_pofile, so |
499 | 1017 | # they are returned with getPOTMsgSetTranslated() call. | 1017 | # they are returned with getPOTMsgSetTranslated() call. |
501 | 1018 | translation1 = self.factory.makeSharedTranslationMessage( | 1018 | self.factory.makeSharedTranslationMessage( |
502 | 1019 | pofile=self.devel_sr_pofile, | 1019 | pofile=self.devel_sr_pofile, |
503 | 1020 | potmsgset=self.potmsgset1, | 1020 | potmsgset=self.potmsgset1, |
504 | 1021 | translations=["Shared translation"]) | 1021 | translations=["Shared translation"]) |
506 | 1022 | translation2 = self.factory.makeSharedTranslationMessage( | 1022 | self.factory.makeSharedTranslationMessage( |
507 | 1023 | pofile=self.devel_sr_pofile, | 1023 | pofile=self.devel_sr_pofile, |
508 | 1024 | potmsgset=self.potmsgset2, | 1024 | potmsgset=self.potmsgset2, |
509 | 1025 | translations=["Another shared translation"]) | 1025 | translations=["Another shared translation"]) |
510 | @@ -1073,22 +1073,22 @@ | |||
511 | 1073 | def test_getPOTMsgSetChangedInLaunchpad_ordering(self): | 1073 | def test_getPOTMsgSetChangedInLaunchpad_ordering(self): |
512 | 1074 | # Suggest a translation on both POTMsgSets in devel_sr_pofile, | 1074 | # Suggest a translation on both POTMsgSets in devel_sr_pofile, |
513 | 1075 | # so they are returned with getPOTMsgSetWithNewSuggestions() call. | 1075 | # so they are returned with getPOTMsgSetWithNewSuggestions() call. |
515 | 1076 | imported1 = self.factory.makeSharedTranslationMessage( | 1076 | self.factory.makeSharedTranslationMessage( |
516 | 1077 | pofile=self.devel_sr_pofile, | 1077 | pofile=self.devel_sr_pofile, |
517 | 1078 | potmsgset=self.potmsgset1, | 1078 | potmsgset=self.potmsgset1, |
518 | 1079 | translations=["Imported"], | 1079 | translations=["Imported"], |
519 | 1080 | is_imported=True) | 1080 | is_imported=True) |
521 | 1081 | translation1 = self.factory.makeSharedTranslationMessage( | 1081 | self.factory.makeSharedTranslationMessage( |
522 | 1082 | pofile=self.devel_sr_pofile, | 1082 | pofile=self.devel_sr_pofile, |
523 | 1083 | potmsgset=self.potmsgset1, | 1083 | potmsgset=self.potmsgset1, |
524 | 1084 | translations=["Changed"], | 1084 | translations=["Changed"], |
525 | 1085 | is_imported=False) | 1085 | is_imported=False) |
527 | 1086 | imported2 = self.factory.makeSharedTranslationMessage( | 1086 | self.factory.makeSharedTranslationMessage( |
528 | 1087 | pofile=self.devel_sr_pofile, | 1087 | pofile=self.devel_sr_pofile, |
529 | 1088 | potmsgset=self.potmsgset2, | 1088 | potmsgset=self.potmsgset2, |
530 | 1089 | translations=["Another imported"], | 1089 | translations=["Another imported"], |
531 | 1090 | is_imported=True) | 1090 | is_imported=True) |
533 | 1091 | translation2 = self.factory.makeSharedTranslationMessage( | 1091 | self.factory.makeSharedTranslationMessage( |
534 | 1092 | pofile=self.devel_sr_pofile, | 1092 | pofile=self.devel_sr_pofile, |
535 | 1093 | potmsgset=self.potmsgset2, | 1093 | potmsgset=self.potmsgset2, |
536 | 1094 | translations=["Another changed"], | 1094 | translations=["Another changed"], |
537 | @@ -1186,11 +1186,11 @@ | |||
538 | 1186 | # This test will go away when potmsgset.sequence goes away. | 1186 | # This test will go away when potmsgset.sequence goes away. |
539 | 1187 | 1187 | ||
540 | 1188 | # Give the method something to search for. | 1188 | # Give the method something to search for. |
542 | 1189 | translation1 = self.factory.makeSharedTranslationMessage( | 1189 | self.factory.makeSharedTranslationMessage( |
543 | 1190 | pofile=self.devel_sr_pofile, | 1190 | pofile=self.devel_sr_pofile, |
544 | 1191 | potmsgset=self.potmsgset1, | 1191 | potmsgset=self.potmsgset1, |
545 | 1192 | translations=["Shared translation"]) | 1192 | translations=["Shared translation"]) |
547 | 1193 | translation2 = self.factory.makeSharedTranslationMessage( | 1193 | self.factory.makeSharedTranslationMessage( |
548 | 1194 | pofile=self.devel_sr_pofile, | 1194 | pofile=self.devel_sr_pofile, |
549 | 1195 | potmsgset=self.potmsgset2, | 1195 | potmsgset=self.potmsgset2, |
550 | 1196 | translations=["Another shared translation"]) | 1196 | translations=["Another shared translation"]) |
551 | @@ -1410,7 +1410,7 @@ | |||
552 | 1410 | # All POFiles with translation credits messages are | 1410 | # All POFiles with translation credits messages are |
553 | 1411 | # returned along with relevant POTMsgSets. | 1411 | # returned along with relevant POTMsgSets. |
554 | 1412 | potemplate1 = self.factory.makePOTemplate() | 1412 | potemplate1 = self.factory.makePOTemplate() |
556 | 1413 | credits_potmsgset = self.factory.makePOTMsgSet( | 1413 | self.factory.makePOTMsgSet( |
557 | 1414 | potemplate1, singular=u'translator-credits', sequence=1) | 1414 | potemplate1, singular=u'translator-credits', sequence=1) |
558 | 1415 | 1415 | ||
559 | 1416 | sr_pofile = self.factory.makePOFile('sr', potemplate=potemplate1) | 1416 | sr_pofile = self.factory.makePOFile('sr', potemplate=potemplate1) |
560 | @@ -1430,7 +1430,7 @@ | |||
561 | 1430 | # If another POTemplate has a translation credits message, it's | 1430 | # If another POTemplate has a translation credits message, it's |
562 | 1431 | # returned as well. | 1431 | # returned as well. |
563 | 1432 | potemplate2 = self.factory.makePOTemplate() | 1432 | potemplate2 = self.factory.makePOTemplate() |
565 | 1433 | kde_credits_potmsgset = self.factory.makePOTMsgSet( | 1433 | self.factory.makePOTMsgSet( |
566 | 1434 | potemplate2, singular=u'Your names', | 1434 | potemplate2, singular=u'Your names', |
567 | 1435 | context=u'NAME OF TRANSLATORS', sequence=1) | 1435 | context=u'NAME OF TRANSLATORS', sequence=1) |
568 | 1436 | sr_kde_pofile = self.factory.makePOFile('sr', potemplate=potemplate2) | 1436 | sr_kde_pofile = self.factory.makePOFile('sr', potemplate=potemplate2) |
569 | @@ -1493,7 +1493,7 @@ | |||
570 | 1493 | def test_getPOFilesByPathAndOrigin_path_mismatch(self): | 1493 | def test_getPOFilesByPathAndOrigin_path_mismatch(self): |
571 | 1494 | # getPOFilesByPathAndOrigin matches on POFile path. | 1494 | # getPOFilesByPathAndOrigin matches on POFile path. |
572 | 1495 | template = self.factory.makePOTemplate() | 1495 | template = self.factory.makePOTemplate() |
574 | 1496 | pofile = template.newPOFile('ta') | 1496 | template.newPOFile('ta') |
575 | 1497 | 1497 | ||
576 | 1498 | not_found = self.pofileset.getPOFilesByPathAndOrigin( | 1498 | not_found = self.pofileset.getPOFilesByPathAndOrigin( |
577 | 1499 | 'tu.po', distroseries=template.distroseries, | 1499 | 'tu.po', distroseries=template.distroseries, |
578 | @@ -1613,7 +1613,7 @@ | |||
579 | 1613 | self.assertEquals(self.pofile.currentCount(), 0) | 1613 | self.assertEquals(self.pofile.currentCount(), 0) |
580 | 1614 | 1614 | ||
581 | 1615 | # Adding an imported translation increases currentCount(). | 1615 | # Adding an imported translation increases currentCount(). |
583 | 1616 | imported = self.factory.makeTranslationMessage( | 1616 | self.factory.makeTranslationMessage( |
584 | 1617 | pofile=self.pofile, | 1617 | pofile=self.pofile, |
585 | 1618 | potmsgset=self.potmsgset, | 1618 | potmsgset=self.potmsgset, |
586 | 1619 | translations=["Imported current"], | 1619 | translations=["Imported current"], |
587 | @@ -1624,7 +1624,7 @@ | |||
588 | 1624 | # Adding a suggestion (i.e. unused translation) | 1624 | # Adding a suggestion (i.e. unused translation) |
589 | 1625 | # will not change the current count when there's | 1625 | # will not change the current count when there's |
590 | 1626 | # already an imported message. | 1626 | # already an imported message. |
592 | 1627 | suggestion = self.factory.makeTranslationMessage( | 1627 | self.factory.makeTranslationMessage( |
593 | 1628 | pofile=self.pofile, | 1628 | pofile=self.pofile, |
594 | 1629 | potmsgset=self.potmsgset, | 1629 | potmsgset=self.potmsgset, |
595 | 1630 | translations=["A suggestion"], | 1630 | translations=["A suggestion"], |
596 | @@ -1640,7 +1640,7 @@ | |||
597 | 1640 | 1640 | ||
598 | 1641 | # Adding a current translation for an untranslated | 1641 | # Adding a current translation for an untranslated |
599 | 1642 | # message increases the count of new translations in LP. | 1642 | # message increases the count of new translations in LP. |
601 | 1643 | current = self.factory.makeTranslationMessage( | 1643 | self.factory.makeTranslationMessage( |
602 | 1644 | pofile=self.pofile, | 1644 | pofile=self.pofile, |
603 | 1645 | potmsgset=self.potmsgset, | 1645 | potmsgset=self.potmsgset, |
604 | 1646 | translations=["Current"]) | 1646 | translations=["Current"]) |
605 | @@ -1651,12 +1651,12 @@ | |||
606 | 1651 | # If we get an 'imported' translation for what | 1651 | # If we get an 'imported' translation for what |
607 | 1652 | # we already have as 'new', it's not considered 'new' | 1652 | # we already have as 'new', it's not considered 'new' |
608 | 1653 | # anymore since it has been synced. | 1653 | # anymore since it has been synced. |
610 | 1654 | current = self.factory.makeTranslationMessage( | 1654 | self.factory.makeTranslationMessage( |
611 | 1655 | pofile=self.pofile, | 1655 | pofile=self.pofile, |
612 | 1656 | potmsgset=self.potmsgset, | 1656 | potmsgset=self.potmsgset, |
613 | 1657 | translations=["Current"]) | 1657 | translations=["Current"]) |
614 | 1658 | # Reimport it but with is_imported=True. | 1658 | # Reimport it but with is_imported=True. |
616 | 1659 | imported = self.factory.makeTranslationMessage( | 1659 | self.factory.makeTranslationMessage( |
617 | 1660 | pofile=self.pofile, | 1660 | pofile=self.pofile, |
618 | 1661 | potmsgset=self.potmsgset, | 1661 | potmsgset=self.potmsgset, |
619 | 1662 | translations=["Current"], | 1662 | translations=["Current"], |
620 | @@ -1669,12 +1669,12 @@ | |||
621 | 1669 | # If we change an 'imported' translation through | 1669 | # If we change an 'imported' translation through |
622 | 1670 | # Launchpad, it's still not considered 'new', | 1670 | # Launchpad, it's still not considered 'new', |
623 | 1671 | # but an 'update' instead. | 1671 | # but an 'update' instead. |
625 | 1672 | imported = self.factory.makeTranslationMessage( | 1672 | self.factory.makeTranslationMessage( |
626 | 1673 | pofile=self.pofile, | 1673 | pofile=self.pofile, |
627 | 1674 | potmsgset=self.potmsgset, | 1674 | potmsgset=self.potmsgset, |
628 | 1675 | translations=["Imported"], | 1675 | translations=["Imported"], |
629 | 1676 | is_imported=True) | 1676 | is_imported=True) |
631 | 1677 | update = self.factory.makeTranslationMessage( | 1677 | self.factory.makeTranslationMessage( |
632 | 1678 | pofile=self.pofile, | 1678 | pofile=self.pofile, |
633 | 1679 | potmsgset=self.potmsgset, | 1679 | potmsgset=self.potmsgset, |
634 | 1680 | translations=["Changed"]) | 1680 | translations=["Changed"]) |
635 | @@ -1722,8 +1722,7 @@ | |||
636 | 1722 | 1722 | ||
637 | 1723 | def test_getTranslationRows_sequence(self): | 1723 | def test_getTranslationRows_sequence(self): |
638 | 1724 | # Test for correct sorting of obsolete messages (where sequence=0). | 1724 | # Test for correct sorting of obsolete messages (where sequence=0). |
641 | 1725 | msgsets = [ | 1725 | [self._createMessageSet(msg) for msg in self.TEST_MESSAGES] |
640 | 1726 | self._createMessageSet(msg) for msg in self.TEST_MESSAGES] | ||
642 | 1727 | for rownum, row in enumerate( | 1726 | for rownum, row in enumerate( |
643 | 1728 | self.pofile.getTranslationRows()): | 1727 | self.pofile.getTranslationRows()): |
644 | 1729 | self.failUnlessEqual( | 1728 | self.failUnlessEqual( |
645 | @@ -1732,5 +1731,117 @@ | |||
646 | 1732 | "(sequence=0) to the end of the file.") | 1731 | "(sequence=0) to the end of the file.") |
647 | 1733 | 1732 | ||
648 | 1734 | 1733 | ||
649 | 1734 | class TestPOFileToTranslationFileDataAdapter(TestCaseWithFactory): | ||
650 | 1735 | """Test POFile being adapted to IPOFileToTranslationFileData.""" | ||
651 | 1736 | |||
652 | 1737 | layer = ZopelessDatabaseLayer | ||
653 | 1738 | |||
654 | 1739 | header = dedent(""" | ||
655 | 1740 | Project-Id-Version: foo | ||
656 | 1741 | Report-Msgid-Bugs-To: | ||
657 | 1742 | POT-Creation-Date: 2007-07-09 03:39+0100 | ||
658 | 1743 | PO-Revision-Date: 2001-09-09 01:46+0000 | ||
659 | 1744 | Last-Translator: Kubla Kahn <kk@pleasure-dome.com> | ||
660 | 1745 | Language-Team: Serbian <sr@li.org> | ||
661 | 1746 | MIME-Version: 1.0 | ||
662 | 1747 | Content-Type: text/plain; charset=UTF-8 | ||
663 | 1748 | Content-Transfer-Encoding: 8bit | ||
664 | 1749 | Plural-Forms: %s""") | ||
665 | 1750 | |||
666 | 1751 | western_plural = "nplurals=2; plural=(n != 1)" | ||
667 | 1752 | other_2_plural = "nplurals=2; plural=(n > 0)" | ||
668 | 1753 | generic_plural = "nplurals=INTEGER; plural=EXPRESSION" | ||
669 | 1754 | serbian3_plural = ("nplurals=3; plural=(n%10==1 && n%100!=11 " | ||
670 | 1755 | "? 0 : n%10>=2 && n%10<=4 && (n% 100<10 || n%100>=20) " | ||
671 | 1756 | "? 1 : 2)") | ||
672 | 1757 | serbian4_plural = ("nplurals=4; plural=(n==1 ? 3 : (n%10==1 && n%100!=11 " | ||
673 | 1758 | "? 0 : n%10>=2 && n%10<=4 && (n% 100<10 || n%100>=20) " | ||
674 | 1759 | "? 1 : 2))") | ||
675 | 1760 | plural_template = "nplurals=%d; plural=%s" | ||
676 | 1761 | |||
677 | 1762 | def _makePOFileWithPlural(self, language_code): | ||
678 | 1763 | pofile = removeSecurityProxy(self.factory.makePOFile(language_code)) | ||
679 | 1764 | self.factory.makePOTMsgSet( | ||
680 | 1765 | pofile.potemplate, singular=u"Foo", plural=u"Bar", sequence=1) | ||
681 | 1766 | return pofile | ||
682 | 1767 | |||
683 | 1768 | def test_header_pluralform_equal(self): | ||
684 | 1769 | # If the number of plural forms in the header is equal to that in the | ||
685 | 1770 | # language entry, use the data from the language entry. | ||
686 | 1771 | sr_pofile = self._makePOFileWithPlural('sr') | ||
687 | 1772 | sr_pofile.header = self.header % self.serbian3_plural | ||
688 | 1773 | |||
689 | 1774 | translation_file_data = getAdapter( | ||
690 | 1775 | sr_pofile, ITranslationFileData, 'all_messages') | ||
691 | 1776 | self.assertEqual(3, translation_file_data.header.number_plural_forms) | ||
692 | 1777 | # The expression from the header starts with a "(", the language entry | ||
693 | 1778 | # does not. | ||
694 | 1779 | self.assertEqual( | ||
695 | 1780 | u"n%10==1 && n%100!=11", | ||
696 | 1781 | translation_file_data.header.plural_form_expression[:20]) | ||
697 | 1782 | |||
698 | 1783 | def test_header_pluralform_larger(self): | ||
699 | 1784 | # If the number of plural forms in the header is larger than in the | ||
700 | 1785 | # language entry, use the data from the header. | ||
701 | 1786 | sr_pofile = self._makePOFileWithPlural('sr') | ||
702 | 1787 | sr_pofile.header = self.header % self.serbian4_plural | ||
703 | 1788 | |||
704 | 1789 | translation_file_data = getAdapter( | ||
705 | 1790 | sr_pofile, ITranslationFileData, 'all_messages') | ||
706 | 1791 | self.assertEqual(4, translation_file_data.header.number_plural_forms) | ||
707 | 1792 | self.assertEqual( | ||
708 | 1793 | u"(n==1 ? 3 : (n%10==1", | ||
709 | 1794 | translation_file_data.header.plural_form_expression[:20]) | ||
710 | 1795 | |||
711 | 1796 | def test_header_pluralform_larger_but_western(self): | ||
712 | 1797 | # If the plural form expression in the header is the standard western | ||
713 | 1798 | # expression, use the data from the language entry if present. | ||
714 | 1799 | # Use Japanese because it has only one plural form which is less | ||
715 | 1800 | # than the 2 the western style has. | ||
716 | 1801 | ja_pofile = self._makePOFileWithPlural('ja') | ||
717 | 1802 | # The expression comes in different forms. | ||
718 | 1803 | for expr in ('(n != 1)', '1 != n', 'n>1', '(1 < n)'): | ||
719 | 1804 | plural_info = self.plural_template % (2, expr) | ||
720 | 1805 | ja_pofile.header = self.header % plural_info | ||
721 | 1806 | |||
722 | 1807 | translation_file_data = getAdapter( | ||
723 | 1808 | ja_pofile, ITranslationFileData, 'all_messages') | ||
724 | 1809 | nplurals_expected = 1 | ||
725 | 1810 | nplurals = translation_file_data.header.number_plural_forms | ||
726 | 1811 | self.assertEqual( | ||
727 | 1812 | nplurals_expected, nplurals, | ||
728 | 1813 | "%d != %d for '%s'" % (nplurals_expected, nplurals, expr)) | ||
729 | 1814 | # The plural form expression for Japanese (or any other language | ||
730 | 1815 | # with just one form) is simply '0'. | ||
731 | 1816 | self.assertEqual( | ||
732 | 1817 | u"0", translation_file_data.header.plural_form_expression) | ||
733 | 1818 | |||
734 | 1819 | def test_header_pluralform_2_but_not_western(self): | ||
735 | 1820 | # If the plural form expression in the header reports two but is not | ||
736 | 1821 | # the standard western expression, use the data from the header. | ||
737 | 1822 | # Use Japanese because it has only one plural form which is less | ||
738 | 1823 | # than the 2 the western style has. | ||
739 | 1824 | ja_pofile = self._makePOFileWithPlural('ja') | ||
740 | 1825 | ja_pofile.header = self.header % self.other_2_plural | ||
741 | 1826 | |||
742 | 1827 | translation_file_data = getAdapter( | ||
743 | 1828 | ja_pofile, ITranslationFileData, 'all_messages') | ||
744 | 1829 | self.assertEqual(2, translation_file_data.header.number_plural_forms) | ||
745 | 1830 | self.assertEqual( | ||
746 | 1831 | u"(n > 0)", translation_file_data.header.plural_form_expression) | ||
747 | 1832 | |||
748 | 1833 | def test_header_pluralform_generic(self): | ||
749 | 1834 | # If the plural form expression in the header is a generic one (no | ||
750 | 1835 | # information), use the data from the language entry if present. | ||
751 | 1836 | ja_pofile = self._makePOFileWithPlural('ja') | ||
752 | 1837 | ja_pofile.header = self.header % self.generic_plural | ||
753 | 1838 | |||
754 | 1839 | translation_file_data = getAdapter( | ||
755 | 1840 | ja_pofile, ITranslationFileData, 'all_messages') | ||
756 | 1841 | self.assertEqual(1, translation_file_data.header.number_plural_forms) | ||
757 | 1842 | self.assertEqual( | ||
758 | 1843 | u"0", translation_file_data.header.plural_form_expression) | ||
759 | 1844 | |||
760 | 1845 | |||
761 | 1735 | def test_suite(): | 1846 | def test_suite(): |
763 | 1736 | return unittest.TestLoader().loadTestsFromName(__name__) | 1847 | return TestLoader().loadTestsFromName(__name__) |
See previous review at https:/ /code.edge. launchpad. net/~henninge/ launchpad/ bug-565294- nplurals