~launchpad-pqm/launchpad/devel

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
Translations URLs
=================

Here we document what URLs different Translations-related objects use.

    >>> from zope.component import getUtility
    >>> from lp.services.webapp import canonical_url

Homepage
--------

The Rosetta homepage.

    >>> from lp.translations.interfaces.translations import (
    ...     IRosettaApplication)
    >>> canonical_url(getUtility(IRosettaApplication))
    u'http://launchpad.dev/translations'

POTemplates and POFiles
-----------------------

    >>> from lp.translations.interfaces.potemplate import IPOTemplateSet
    >>> from lp.translations.interfaces.translationgroup import (
    ...     ITranslationGroupSet)

Most Rosetta pages hang off IPOTemplateSubset objects, of which there are two
varieties: distribution and upstream.

First, the distribution kind.  We'll need the source package name.

    >>> from lp.registry.interfaces.sourcepackagename import (
    ...     ISourcePackageNameSet)
    >>> from lp.registry.interfaces.distribution import IDistributionSet
    >>> sourcepackagenameset = getUtility(ISourcePackageNameSet)
    >>> sourcepackagename = sourcepackagenameset['evolution']
    >>> distroset = getUtility(IDistributionSet)
    >>> ubuntu = distroset['ubuntu']
    >>> hoary = ubuntu.getSeries('hoary')

And here's our subset.

    >>> potemplateset = getUtility(IPOTemplateSet)
    >>> potemplatesubset = potemplateset.getSubset(
    ...     distroseries=hoary, sourcepackagename=sourcepackagename)

    >>> canonical_url(potemplatesubset)
    u'http://launchpad.dev/ubuntu/hoary/+source/evolution/+pots'

We can get a particular PO template for this source package by its PO template
name.

    >>> potemplate = potemplatesubset['evolution-2.2']
    >>> canonical_url(potemplate)
    u'http://translations.../hoary/+source/evolution/+pots/evolution-2.2'

And we can get a particular PO file for this PO template by its language code.

    >>> pofile = potemplate.getPOFileByLang('es')
    >>> canonical_url(pofile)
    u'http://translations.../hoary/+source/evolution/+pots/evolution-2.2/es'

Also, we can get the url to a translation message.

    >>> potmsgset = potemplate.getPOTMsgSetBySequence(1)
    >>> translationmessage = potmsgset.getCurrentTranslation(
    ...     pofile.potemplate, pofile.language, potemplate.translation_side)
    >>> translationmessage.setPOFile(pofile)
    >>> print canonical_url(translationmessage)
    http://transl.../hoary/+source/evolution/+pots/evolution-2.2/es/1

Even for a dummy one.

    >>> potmsgset = potemplate.getPOTMsgSetBySequence(20)
    >>> translationmessage = potmsgset.getCurrentTranslationMessageOrDummy(
    ...     pofile)
    >>> print canonical_url(translationmessage)
    http://transl.../hoary/+source/evolution/+pots/evolution-2.2/es/20

Upstream POTemplateSubsets work in much the same way, except they hang off a
product series.  Let's get a product series.

Now we can get an upstream subset and do the same sorts of thing as we did
with the distro subset.

    >>> from lp.registry.interfaces.product import IProductSet
    >>> productset = getUtility(IProductSet)
    >>> evolution_product = productset['evolution']
    >>> evolution_trunk_series = evolution_product.getSeries('trunk')

    >>> potemplatesubset = potemplateset.getSubset(
    ...     productseries=evolution_trunk_series)
    >>> potemplate = potemplatesubset['evolution-2.2']
    >>> canonical_url(potemplate)
    u'http://translations.launchpad.dev/evolution/trunk/+pots/evolution-2.2'

    >>> pofile = potemplate.getPOFileByLang('es')
    >>> canonical_url(pofile)
    u'http://translations.../evolution/trunk/+pots/evolution-2.2/es'

Also, we can get the url to a dummy one

    >>> potmsgset = potemplate.getPOTMsgSetBySequence(1)
    >>> translationmessage = potmsgset.getCurrentTranslation(
    ...     pofile.potemplate, pofile.language, potemplate.translation_side)
    >>> translationmessage.setPOFile(pofile)
    >>> print canonical_url(translationmessage)
    http://translations.../evolution/trunk/+pots/evolution-2.2/es/1

Even for a dummy PO msgset

    >>> potmsgset = potemplate.getPOTMsgSetBySequence(20)
    >>> translationmessage = potmsgset.getCurrentTranslationMessageOrDummy(
    ...     pofile)
    >>> print canonical_url(translationmessage)
    http://translations.../evolution/trunk/+pots/evolution-2.2/es/20


Translation groups
------------------

Rosetta also has translation groups.

    >>> canonical_url(getUtility(ITranslationGroupSet))
    u'http://translations.launchpad.dev/+groups'

    >>> canonical_url(factory.makeTranslationGroup(name='test'))
    u'http://translations.launchpad.dev/+groups/test'


Distribution, DistroSeries and DistroSeriesLanguage
---------------------------------------------------

Distribution and distribution series default to the main vhost.

    >>> distribution = factory.makeDistribution(
    ...     name='boo')
    >>> canonical_url(distribution)
    u'http://launchpad.dev/boo'

    >>> distroseries = factory.makeDistroSeries(
    ...     name='bah', distribution=distribution)
    >>> canonical_url(distroseries)
    u'http://launchpad.dev/boo/bah'

DistroSeriesLanguage objects have their URLs on translations vhost.

    >>> from lp.services.worlddata.interfaces.language import ILanguageSet
    >>> from lp.translations.interfaces.distroserieslanguage import (
    ...     IDistroSeriesLanguageSet)
    >>> serbian = getUtility(ILanguageSet)['sr']

    >>> boo_bah_serbian = getUtility(IDistroSeriesLanguageSet).getDummy(
    ...     distroseries, serbian)
    >>> canonical_url(boo_bah_serbian)
    u'http://translations.launchpad.dev/boo/bah/+lang/sr'

Product, ProductSeries and ProductSeriesLanguage
---------------------------------------------------

Product and product series default to the main vhost.

    >>> product = factory.makeProduct(
    ...     name='coo')
    >>> canonical_url(product)
    u'http://launchpad.dev/coo'

    >>> productseries = factory.makeProductSeries(
    ...     name='cah', product=product)
    >>> canonical_url(productseries)
    u'http://launchpad.dev/coo/cah'

ProductSeriesLanguage objects have their URLs on translations vhost.

    >>> from lp.translations.interfaces.productserieslanguage import (
    ...     IProductSeriesLanguageSet)

    >>> psl_set = getUtility(IProductSeriesLanguageSet)
    >>> coo_cah_serbian = psl_set.getProductSeriesLanguage(
    ...     productseries, serbian)
    >>> canonical_url(coo_cah_serbian)
    u'http://translations.launchpad.dev/coo/cah/+lang/sr'