~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/doc/distroseries-language.txt

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2004-06-28 10:08:03 UTC
  • mfrom: (unknown (missing))
  • Revision ID: Arch-1:rocketfuel@canonical.com%soyuz--devel--0--patch-8
add ./sourcecode directory
Patches applied:

 * david.allouche@canonical.com--2004/soyuz--devel--0--base-0
   tag of rocketfuel@canonical.com/soyuz--devel--0--patch-7

 * david.allouche@canonical.com--2004/soyuz--devel--0--patch-1
   add ./sourcecode directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
DistroSeriesLanguage
2
 
====================
3
 
 
4
 
This is a special class which encapsulates the information associated with a
5
 
particular language and distroseries.
6
 
 
7
 
First we need to know which distroserieslanguage we are working with. We
8
 
will work with spanish in Hoary first.
9
 
 
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")
19
 
    >>> hoary.name
20
 
    u'hoary'
21
 
    >>> spanish = getUtility(ILanguageSet)['es']
22
 
    >>> hoary_spanish = hoary.getDistroSeriesLanguage(spanish)
23
 
 
24
 
DistroSeriesLanguage provides basic `title` describing what is it about.
25
 
 
26
 
    >>> hoary_spanish.title
27
 
    u'Spanish translations of Ubuntu Hoary'
28
 
 
29
 
In DistroSeriesLanguage.pofiles we find real POFiles for the given
30
 
DistroSeries in the given language.  That is, translations that actually
31
 
contain messages.
32
 
 
33
 
    >>> for po in hoary_spanish.pofiles:
34
 
    ...     print po.potemplate.name
35
 
    evolution-2.2
36
 
    pmount
37
 
    pkgconf-mozilla
38
 
    man
39
 
 
40
 
There are however more templates than the ones that have messages:
41
 
 
42
 
    >>> hoary_templates = list(hoary.getCurrentTranslationTemplates())
43
 
    >>> for template in hoary_templates:
44
 
    ...     print template.name
45
 
    evolution-2.2
46
 
    man
47
 
    man
48
 
    pkgconf-mozilla
49
 
    pmount
50
 
 
51
 
We can ask the DistroSeriesLanguage to fetch existing POFiles for these
52
 
templates where they exist, or create matching DummyPOFiles where they
53
 
don't.
54
 
 
55
 
    >>> from zope.security.proxy import removeSecurityProxy
56
 
    >>> def print_augmented_pofiles(distroserieslanguage, templates):
57
 
    ...     """Print `POFile`s for each of `templates`.
58
 
    ...
59
 
    ...     Creates `DummyPOFile`s where needed.  Prints types.
60
 
    ...     """
61
 
    ...     for pofile in distroserieslanguage.getPOFilesFor(templates):
62
 
    ...         print "%s (%s) %s" % (
63
 
    ...             pofile.potemplate.name, pofile.language.code,
64
 
    ...             removeSecurityProxy(pofile).__class__)
65
 
 
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'>
72
 
 
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
75
 
DummyPOFile.
76
 
 
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
79
 
listing.
80
 
 
81
 
    >>> for potemplate in hoary.getTranslationTemplates():
82
 
    ...     print potemplate.name
83
 
    evolution-2.2
84
 
    disabled-template
85
 
    man
86
 
    man
87
 
    pkgconf-mozilla
88
 
    pmount
89
 
 
90
 
This is the one obsolete template.
91
 
 
92
 
    >>> potemplate = hoary.getTranslationTemplateByName('disabled-template')
93
 
    >>> print potemplate.iscurrent
94
 
    False
95
 
 
96
 
Also, we can see that the template has an Spanish translation that
97
 
hoary_spanish.pofiles is hiding as expected.
98
 
 
99
 
    >>> print potemplate.getPOFileByLang('es').title
100
 
    Spanish (es) translation of disabled-template in Ubuntu Hoary package
101
 
    "evolution"
102
 
 
103
 
We also have DummyDistroSeriesLanguages.
104
 
 
105
 
    >>> amharic = getUtility(ILanguageSet)['am']
106
 
    >>> hoary_amharic = hoary.getDistroSeriesLanguageOrDummy(amharic)
107
 
    >>> print hoary_amharic.__class__
108
 
    <class '...DummyDistroSeriesLanguage'>
109
 
 
110
 
English is not a translatable language because we store the source messages
111
 
as English. Thus English cannot be a DummyDistroSeriesLanguage.
112
 
 
113
 
    >>> english = getUtility(ILanguageSet)['en']
114
 
    >>> hoary_english = hoary.getDistroSeriesLanguageOrDummy(english)
115
 
    Traceback (most recent call last):
116
 
    ...
117
 
    AssertionError: English is not a translatable language.
118
 
 
119
 
A DummyDistroSeriesLanguage gives you the same set of templates to
120
 
translate as a regular DistroSeriesLanguage would.
121
 
 
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'>
128
 
 
129
 
Now, we should test that a DummyDistroSeriesLanguage implements the full
130
 
interface of a normal DistroSeriesLanguage.
131
 
 
132
 
NB IF THIS FAILS then it means that the DistroSeriesLanguage object has
133
 
been extended, and the DummyDistroSeriesLanguage has not been similarly
134
 
extended.
135
 
 
136
 
    >>> print IDistroSeriesLanguage.providedBy(hoary_amharic)
137
 
    True
138
 
 
139
 
 
140
 
POTemplate Sorting
141
 
------------------
142
 
 
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
145
 
tests show that).
146
 
 
147
 
Now we will show that the priority can dominate the sort order.
148
 
 
149
 
    >>> potemplates = list(hoary.getCurrentTranslationTemplates())
150
 
    >>> evo = potemplates[0]
151
 
    >>> print evo.name
152
 
    evolution-2.2
153
 
    >>> man1 = potemplates[1]
154
 
    >>> print man1.name
155
 
    man
156
 
    >>> man2 = potemplates[2]
157
 
    >>> print man2.name
158
 
    man
159
 
    >>> mozconf = potemplates[3]
160
 
    >>> print mozconf.name
161
 
    pkgconf-mozilla
162
 
    >>> pm = potemplates[4]
163
 
    >>> print pm.name
164
 
    pmount
165
 
 
166
 
OK, so we have the five templates. Let's set their priorities and see if
167
 
that changes the default sort order.
168
 
 
169
 
We need to login so we can poke at the potemplates.
170
 
 
171
 
    >>> from canonical.launchpad.ftests import login
172
 
    >>> login('foo.bar@canonical.com')
173
 
 
174
 
We set their priorities so that the lowest alpha-sort one has the highest
175
 
priority.
176
 
 
177
 
    >>> evo.priority = 5
178
 
    >>> man1.priority = 6
179
 
    >>> man2.priority = 7
180
 
    >>> mozconf.priority = 8
181
 
    >>> pm.priority = 9
182
 
    >>> from canonical.database.sqlbase import flush_database_updates
183
 
    >>> flush_database_updates()
184
 
 
185
 
And now we can confirm that priority does in fact dominate:
186
 
 
187
 
    >>> for pot in hoary.getCurrentTranslationTemplates():
188
 
    ...     print pot.priority, pot.name
189
 
    9 pmount
190
 
    8 pkgconf-mozilla
191
 
    7 man
192
 
    6 man
193
 
    5 evolution-2.2
194
 
 
195
 
And now this priority should also dominate the distroseries language
196
 
pofile sort order:
197
 
 
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'>
205