4
This is a special class which encapsulates the information associated with a
5
particular language and distroseries.
7
First we need to know which distroserieslanguage we are working with. We
8
will work with spanish in Hoary first.
10
>>> from zope.component import getUtility
11
>>> from lp.registry.interfaces.distribution import IDistributionSet
12
>>> from lp.registry.interfaces.distroseries import IDistroSeriesSet
13
>>> from lp.services.worlddata.interfaces.language import ILanguageSet
14
>>> from lp.translations.interfaces.distroserieslanguage import (
15
... IDistroSeriesLanguage)
16
>>> distroseriesset = getUtility(IDistroSeriesSet)
17
>>> ubuntu = getUtility(IDistributionSet).getByName("ubuntu")
18
>>> hoary = distroseriesset.queryByName(ubuntu, "hoary")
21
>>> spanish = getUtility(ILanguageSet)['es']
22
>>> hoary_spanish = hoary.getDistroSeriesLanguage(spanish)
24
DistroSeriesLanguage provides basic `title` describing what is it about.
26
>>> hoary_spanish.title
27
u'Spanish translations of Ubuntu Hoary'
29
In DistroSeriesLanguage.pofiles we find real POFiles for the given
30
DistroSeries in the given language. That is, translations that actually
33
>>> for po in hoary_spanish.pofiles:
34
... print po.potemplate.name
40
There are however more templates than the ones that have messages:
42
>>> hoary_templates = list(hoary.getCurrentTranslationTemplates())
43
>>> for template in hoary_templates:
44
... print template.name
51
We can ask the DistroSeriesLanguage to fetch existing POFiles for these
52
templates where they exist, or create matching DummyPOFiles where they
55
>>> from zope.security.proxy import removeSecurityProxy
56
>>> def print_augmented_pofiles(distroserieslanguage, templates):
57
... """Print `POFile`s for each of `templates`.
59
... Creates `DummyPOFile`s where needed. Prints types.
61
... for pofile in distroserieslanguage.getPOFilesFor(templates):
62
... print "%s (%s) %s" % (
63
... pofile.potemplate.name, pofile.language.code,
64
... removeSecurityProxy(pofile).__class__)
66
>>> print_augmented_pofiles(hoary_spanish, hoary_templates)
67
evolution-2.2 (es) <class '...pofile.POFile'>
68
man (es) <class '...pofile.POFile'>
69
man (es) <class '...pofile.DummyPOFile'>
70
pkgconf-mozilla (es) <class '...pofile.POFile'>
71
pmount (es) <class '...pofile.POFile'>
73
Note that the sorting is by template name, and there are two 'man'
74
templates of which one has a real translation and the other uses a
77
When we ask for the whole list of templates, including non-current ones,
78
we see one extra template that was not shown in the DistroSeriesLanguage
81
>>> for potemplate in hoary.getTranslationTemplates():
82
... print potemplate.name
90
This is the one obsolete template.
92
>>> potemplate = hoary.getTranslationTemplateByName('disabled-template')
93
>>> print potemplate.iscurrent
96
Also, we can see that the template has an Spanish translation that
97
hoary_spanish.pofiles is hiding as expected.
99
>>> print potemplate.getPOFileByLang('es').title
100
Spanish (es) translation of disabled-template in Ubuntu Hoary package
103
We also have DummyDistroSeriesLanguages.
105
>>> amharic = getUtility(ILanguageSet)['am']
106
>>> hoary_amharic = hoary.getDistroSeriesLanguageOrDummy(amharic)
107
>>> print hoary_amharic.__class__
108
<class '...DummyDistroSeriesLanguage'>
110
English is not a translatable language because we store the source messages
111
as English. Thus English cannot be a DummyDistroSeriesLanguage.
113
>>> english = getUtility(ILanguageSet)['en']
114
>>> hoary_english = hoary.getDistroSeriesLanguageOrDummy(english)
115
Traceback (most recent call last):
117
AssertionError: English is not a translatable language.
119
A DummyDistroSeriesLanguage gives you the same set of templates to
120
translate as a regular DistroSeriesLanguage would.
122
>>> print_augmented_pofiles(hoary_amharic, hoary_templates)
123
evolution-2.2 (am) <class '...pofile.DummyPOFile'>
124
man (am) <class '...pofile.DummyPOFile'>
125
man (am) <class '...pofile.DummyPOFile'>
126
pkgconf-mozilla (am) <class '...pofile.DummyPOFile'>
127
pmount (am) <class '...pofile.DummyPOFile'>
129
Now, we should test that a DummyDistroSeriesLanguage implements the full
130
interface of a normal DistroSeriesLanguage.
132
NB IF THIS FAILS then it means that the DistroSeriesLanguage object has
133
been extended, and the DummyDistroSeriesLanguage has not been similarly
136
>>> print IDistroSeriesLanguage.providedBy(hoary_amharic)
143
In general, potemplates should be sorted by priority (descending) then name.
144
The sample data all has priority 0. So it's all sorted by name (the above
147
Now we will show that the priority can dominate the sort order.
149
>>> potemplates = list(hoary.getCurrentTranslationTemplates())
150
>>> evo = potemplates[0]
153
>>> man1 = potemplates[1]
156
>>> man2 = potemplates[2]
159
>>> mozconf = potemplates[3]
160
>>> print mozconf.name
162
>>> pm = potemplates[4]
166
OK, so we have the five templates. Let's set their priorities and see if
167
that changes the default sort order.
169
We need to login so we can poke at the potemplates.
171
>>> from canonical.launchpad.ftests import login
172
>>> login('foo.bar@canonical.com')
174
We set their priorities so that the lowest alpha-sort one has the highest
178
>>> man1.priority = 6
179
>>> man2.priority = 7
180
>>> mozconf.priority = 8
182
>>> from canonical.database.sqlbase import flush_database_updates
183
>>> flush_database_updates()
185
And now we can confirm that priority does in fact dominate:
187
>>> for pot in hoary.getCurrentTranslationTemplates():
188
... print pot.priority, pot.name
195
And now this priority should also dominate the distroseries language
198
>>> print_augmented_pofiles(
199
... hoary_amharic, hoary.getCurrentTranslationTemplates())
200
pmount (am) <class '...pofile.DummyPOFile'>
201
pkgconf-mozilla (am) <class '...pofile.DummyPOFile'>
202
man (am) <class '...pofile.DummyPOFile'>
203
man (am) <class '...pofile.DummyPOFile'>
204
evolution-2.2 (am) <class '...pofile.DummyPOFile'>