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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0213
"""Custom language code."""
__metaclass__ = type
__all__ = [
'ICustomLanguageCode',
'IHasCustomLanguageCodes',
]
from zope.interface import Interface
from zope.schema import (
Bool,
Choice,
Int,
Object,
Set,
TextLine,
)
from zope.schema.interfaces import IObject
from canonical.launchpad import _
from lp.registry.interfaces.distribution import IDistribution
from lp.registry.interfaces.product import IProduct
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
class ICustomLanguageCode(Interface):
"""`CustomLanguageCode` interface."""
id = Int(title=_("ID"), required=True, readonly=True)
product = Object(
title=_("Product"), required=False, readonly=True, schema=IProduct)
distribution = Object(
title=_("Distribution"), required=False, readonly=True,
schema=IDistribution)
sourcepackagename = Object(
title=_("Source package name"), required=False, readonly=True,
schema=ISourcePackageName)
language_code = TextLine(title=_("Language code"),
description=_("Language code to treat as special."),
required=True, readonly=False)
language = Choice(
title=_("Language"), required=False, readonly=False,
vocabulary='Language',
description=_("Language to map this code to. "
"Leave empty to drop translations for this code."))
# Reference back to the IHasCustomLanguageCodes.
translation_target = Object(
title=_("Context this custom language code applies to"),
required=True, readonly=True, schema=IObject)
class IHasCustomLanguageCodes(Interface):
"""A context that can have custom language codes attached.
Implemented by `Product` and `SourcePackage`.
"""
custom_language_codes = Set(
title=_("Custom language codes"),
description=_("Translations for these language codes are re-routed."),
value_type=Object(schema=ICustomLanguageCode),
required=False, readonly=False)
has_custom_language_codes = Bool(
title=_("There are custom language codes in this context."),
readonly=True, required=True)
def getCustomLanguageCode(language_code):
"""Retrieve `CustomLanguageCode` for `language_code`.
:return: a `CustomLanguageCode`, or None.
"""
def createCustomLanguageCode(language_code, language):
"""Create `CustomLanguageCode`.
:return: the new `CustomLanguageCode` object.
"""
def removeCustomLanguageCode(language_code):
"""Remove `CustomLanguageCode`.
:param language_code: A `CustomLanguageCode` object.
"""
|