~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
# Copyright 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Interface for objects that translation templates can belong to."""

__metaclass__ = type
__all__ = [
    'IHasTranslationTemplates',
    ]

from lazr.restful.declarations import (
    export_read_operation,
    operation_for_version,
    operation_returns_collection_of,
    )
from zope.interface import Interface
from zope.schema import Bool

from lp import _


class IHasTranslationTemplates(Interface):
    """An entity that has translation templates attached.

    Examples include `ISourcePackage`, `IDistroSeries`, and `IProductSeries`.
    """

    has_translation_templates = Bool(
        title=_("Does this object have any translation templates?"),
        readonly=True)

    has_current_translation_templates = Bool(
        title=_("Does this object have current translation templates?"),
        readonly=True)

    has_obsolete_translation_templates = Bool(
        title=_("Does this object have obsolete translation templates?"),
        readonly=True)

    has_sharing_translation_templates = Bool(
        title=_("Does this object have sharing translation templates?"),
        readonly=True)

    has_translation_files = Bool(
        title=_("Does this object have translation files?"),
        readonly=True)

    def getTemplatesCollection():
        """Return templates as a `TranslationTemplatesCollection`.

        The collection selects all `POTemplate`s attached to the
        translation target that implements this interface.
        """

    def getSharingPartner():
        """Return the object on the other side of the packaging link.

        Return the object that is sharing translations with this one on the
        other side of a packaging link. It must also implement this interface.
        """

    def getCurrentTemplatesCollection():
        """Return `TranslationTemplatesCollection` of current templates.

        A translation template is considered active when
        `IPOTemplate`.iscurrent flag is set to True.
        """

    def getCurrentTranslationTemplates(just_ids=False):
        """Return an iterator over all active translation templates.

        :param just_ids: If True, return only the `POTemplate.id` rather
            than the full `POTemplate`.  Used to save time on retrieving
            and deserializing the objects from the database.

        A translation template is considered active when
        `IPOTemplate`.iscurrent is set to True.
        """

    def getCurrentTranslationFiles(just_ids=False):
        """Return an iterator over all active translation files.

        A translation file is active if it's attached to an
        active translation template.
        """

    @export_read_operation()
    @operation_returns_collection_of(Interface)
    @operation_for_version('beta')
    def getTranslationTemplates():
        """Return an iterator over all its translation templates.

        The returned templates are either obsolete or current.

        :return: A sequence of `IPOTemplate`.
        """

    def getTranslationTemplateByName(name):
        """Return the template with the given name or None."""

    def getTranslationTemplateFormats():
        """A list of native formats for all current translation templates.
        """

    def getTemplatesAndLanguageCounts():
        """List tuples of `POTemplate` and its language count.

        A template's language count is the number of `POFile`s that
        exist for it.
        """