~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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# pylint: disable-msg=E0211,E0213

"""Common file format interfaces shared across all formats."""


from zope.interface import Interface
from zope.schema import (
    Bool,
    Choice,
    Datetime,
    Int,
    List,
    Object,
    Set,
    Text,
    TextLine,
    )

from lp.translations.interfaces.translationfileformat import (
    TranslationFileFormat,
    )


__metaclass__ = type

__all__ = [
    'ITranslationFileData',
    'ITranslationHeaderData',
    'ITranslationMessageData',
    'TranslationImportExportBaseException',
    ]


class TranslationImportExportBaseException(Exception):
    """Base exception for all import/export exceptions."""


class ITranslationHeaderData(Interface):
    """Translation header interface."""

    is_fuzzy = Bool(
        title=u'A flag indicating whether the header needs to be edited',
        required=True, readonly=True)

    template_creation_date = Datetime(
        title=u'When was created the template used in this file.',
        required=True, readonly=True)

    translation_revision_date = Datetime(
        title=u'When the translation resource was last revised or None.',
        required=True)

    language_team = TextLine(
        title=u'The language team in charge of this translation.',
        required=True, readonly=True)

    has_plural_forms = Bool(
        title=u'Whether this file contains plural forms.', required=True)

    number_plural_forms = Int(
        title=u'Number of plural forms.', required=True)

    plural_form_expression = TextLine(
        title=u'The plural form expression defined in this file or None.',
        required=True)

    charset = TextLine(
        title=u'Charset used to encode the content in its native form.',
        required=True)

    launchpad_export_date = Datetime(
        title=u'When this file was last exported from Launchpad or None.',
        required=True)

    comment = Text(
        title=u'Header comment',
        description=u'''
            It usually has copyright information and list of contributors.
            ''',
        required=True)

    def getRawContent():
        """Return header raw content in its native file format."""

    def updateFromTemplateHeader(template_header):
        """Update header with some content from the given template header.

        :param template_header: An `ITranslationHeaderData` for an
            `IPOTemplate`.

        The fields copied depend on the file format.
        """

    def getLastTranslator():
        """Return a tuple of name and email for last translator.

        name and/or email would be None if there is no such information.
        """

    def setLastTranslator(email, name=None):
        """Set last translator information.

        :param email: A string with the email address for last translator.
        :param name: The name for the last translator or None.
        """


class ITranslationMessageData(Interface):
    """Translation message interface."""

    context = Text(
        title=u'The context of the message.',
        required=True, readonly=True)

    msgid_singular = Text(
        title=u'The singular msgid of the message.', required=True,
        readonly=True)

    singular_text = Text(
        title=(
            u'The message singular text. Usually matches msgid_singular.'),
            required=False, readonly=True)

    msgid_plural = Text(
        title=u'The plural msgid of the message or None.',
        required=True, readonly=True)

    plural_text = Text(
        title=(
            u'The message plural text. Usually matches msgid_plural.'),
            required=False, readonly=True)

    translations = List(
        title=u'The translations of the message.', required=True,
        readonly=True)

    comment = Text(
        title=u'Comments added by a translator.', required=True,
        readonly=True)

    source_comment = Text(
        title=u'Comments added by the developer to help translators.',
        required=True, readonly=True)

    file_references = Text(
        title=u'File references from where this message was extracted."',
        required=True, readonly=True)

    flags = Set(
        title=u'Message flags needed to validate its translation.',
        required=True, readonly=True)

    is_obsolete = Bool(
        title=u"Is this message obsolete?", required=True, readonly=True)


class ITranslationFileData(Interface):
    """Parsed translation template file interface."""
    format = Choice(
        title=u"This file's translation file format.", required=True,
        vocabulary=TranslationFileFormat)

    header = Object(
        title=u'An `ITranslationHeaderData` for the parsed file.',
        required=True, schema=ITranslationHeaderData)

    messages = List(
        title=u'ITranslationMessageData objects included in the parsed file.',
        required=True, readonly=True)

    path = TextLine(
        title=u'The path directory where this file is stored.',
        required=True, readonly=True)

    translation_domain = TextLine(
        title=u'Translation domain used for this translation file',
        description=u'''
            It would be used to find its content on the file system, when
            its associated application is executed.
            ''',
        required=True, readonly=True)

    is_template = Bool(
        title=u"Is this entry a translation template?", required=True,
        readonly=True)

    language_code = TextLine(
        title=u'Language iso code for this translation file',
        description=u'''
            Language iso code for this translation file or None either if it's
            unknown or is_template flag is set.
            ''',
        required=True, readonly=True)

    syntax_warnings = Set(
        title=u"Syntax warnings", required=False, readonly=True)