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
|
Translation Groups
==================
>>> from zope.component import getUtility
>>> from lp.testing import login
>>> login('daf@canonical.com')
Here are various sets of things that we'll need.
>>> from lp.translations.interfaces.translationgroup import (
... ITranslationGroupSet)
>>> translation_group_set = getUtility(ITranslationGroupSet)
>>> from lp.registry.interfaces.person import IPersonSet
>>> person_set = getUtility(IPersonSet)
>>> from lp.registry.interfaces.product import IProductSet
>>> product_set = getUtility(IProductSet)
>>> from lp.translations.interfaces.translator import ITranslatorSet
>>> translator_set = getUtility(ITranslatorSet)
>>> from lp.services.worlddata.interfaces.language import ILanguageSet
>>> language_set = getUtility(ILanguageSet)
>>> from lp.translations.interfaces.potemplate import IPOTemplateSet
>>> potemplate_set = getUtility(IPOTemplateSet)
Here are Carlos and No Privileges Person. Carlos manages the translation group
for Evolution, and No Privileges Person is a translator.
>>> carlos = person_set.getByName('carlos')
>>> no_priv = person_set.getByName('no-priv')
Here's our translation group.
>>> group = translation_group_set.new(
... name='foo-translators',
... title='Foo Translators',
... summary='Foo Translators',
... translation_guide_url='https://help.launchpad.net/',
... owner=carlos)
We can access all details of the new TranslationGroup.
>>> group.title
u'Foo Translators'
>>> group.translation_guide_url
u'https://help.launchpad.net/'
>>> group.owner.name
u'carlos'
Let's make it the translation group for Evolution.
>>> evolution = product_set['evolution']
>>> evolution.translationgroup = group
Let's only allow translators from that group to translate.
>>> from lp.translations.enums import TranslationPermission
>>> evolution.translationpermission = TranslationPermission.CLOSED
No Privileges Person isn't allowed to translate into Welsh.
>>> series = evolution.getSeries('trunk')
>>> subset = potemplate_set.getSubset(productseries=series)
>>> potemplate = subset['evolution-2.2']
>>> pofile = potemplate.newPOFile('cy')
>>> pofile.canEditTranslations(no_priv)
False
Let's add him to the group.
>>> welsh = language_set['cy']
>>> no_priv_translator = translator_set.new(
... translationgroup=group,
... language=welsh,
... translator=no_priv)
No Privileges Person *is* allowed to translate into Welsh.
>>> pofile.canEditTranslations(no_priv)
True
Each group has a list of top_projects that it translates. It is just
a shorter list of all the projects. At the moment, it lists only
Evolution, and a number_of_remaining_projects (those not shown in the
top_projects list) is zero.
>>> set(group.top_projects) == set([evolution])
True
>>> group.number_of_remaining_projects
0
Making a distribution use the translation group puts it into top_projects.
>>> distro = factory.makeDistribution()
>>> distro.translationgroup = group
>>> set(group.top_projects) == set([evolution, distro])
True
>>> group.number_of_remaining_projects
0
Project groups, if they use this translation group, appear in the
top_projects too.
>>> project = factory.makeProject()
>>> project.translationgroup = group
>>> set(group.top_projects) == set([evolution, distro, project])
True
>>> group.number_of_remaining_projects
0
If we add 2 projects more than what the group.TOP_PROJECTS_LIMIT is,
the top_projects list is shortened and a number_of_remaining_projects tells
us how many other projects are there (2).
>>> from zope.security.proxy import removeSecurityProxy
>>> limit = removeSecurityProxy(group).TOP_PROJECTS_LIMIT
>>> current = len(group.top_projects)
>>> goal = limit + 2 - current
>>> while goal > 0:
... product = factory.makeProduct()
... product.translationgroup = group
... goal -= 1
>>> len(group.top_projects) == limit
True
>>> group.number_of_remaining_projects
2
We can use TranslationGroupSet to check what translation groups a person
is a part of:
>>> for group in translation_group_set.getByPerson(carlos):
... print group.name
testing-translation-team
>>> for group in translation_group_set.getByPerson(no_priv):
... print group.name
foo-translators
>>> translators = getUtility(ITranslatorSet)
>>> for trans in translators.getByTranslator(carlos):
... print trans.language.code
... print trans.translationgroup.name
... print trans.style_guide_url
es
testing-translation-team
None
>>> for trans in translators.getByTranslator(no_priv):
... print trans.language.code
... print trans.translationgroup.name
... print trans.style_guide_url
cy
foo-translators
None
fetchTranslatorData
-------------------
Use fetchTranslator data to get all members of a translation group,
with their respective assigned languages, in one go. This saves
repeated querying.
>>> group = factory.makeTranslationGroup()
>>> list(group.fetchTranslatorData())
[]
>>> de_team = factory.makeTeam(name='de-team')
>>> nl_team = factory.makeTeam(name='nl-team')
>>> la_team = factory.makeTeam(name='la-team')
>>> de_translator = factory.makeTranslator('de', group, person=de_team)
>>> nl_translator = factory.makeTranslator('nl', group, person=nl_team)
>>> la_translator = factory.makeTranslator('la', group, person=la_team)
>>> transaction.commit()
The method returns tuples of respectively a Translator ("translation
group membership entry"), its language, and the actual team or person
assigned to that language.
>>> for (translator, language, team) in group.fetchTranslatorData():
... print translator.language.code, language.code, team.name
nl nl nl-team
de de de-team
la la la-team
The members are sorted by language name in English.
>>> for (translator, language, person) in group.fetchTranslatorData():
... print language.englishname
Dutch
German
Latin
|