~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/interfaces/languages.py

  • Committer: klm
  • Date: 1998-01-07 21:21:35 UTC
  • Revision ID: vcs-imports@canonical.com-19980107212135-sv0y521ps0xye37r
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012 by the Free Software Foundation, Inc.
2
 
#
3
 
# This file is part of GNU Mailman.
4
 
#
5
 
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
 
# the terms of the GNU General Public License as published by the Free
7
 
# Software Foundation, either version 3 of the License, or (at your option)
8
 
# any later version.
9
 
#
10
 
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 
# more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along with
16
 
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
"""Interfaces for managing languages."""
19
 
 
20
 
from __future__ import absolute_import, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
 
__all__ = [
24
 
    'ILanguage',
25
 
    'ILanguageManager',
26
 
    ]
27
 
 
28
 
 
29
 
from zope.interface import Interface, Attribute
30
 
 
31
 
 
32
 
 
33
 
class ILanguage(Interface):
34
 
    """The representation of a language."""
35
 
 
36
 
    code = Attribute('The 2-character language code.')
37
 
 
38
 
    charset = Attribute('The character set or encoding for this language.')
39
 
 
40
 
    description = Attribute("The language's description.")
41
 
 
42
 
 
43
 
 
44
 
class ILanguageManager(Interface):
45
 
    """A language manager.
46
 
 
47
 
    Current, disabling languages is not supported.
48
 
    """
49
 
 
50
 
    def add(code, charset, description):
51
 
        """Teach the language manager about a language.
52
 
 
53
 
        :param code: The short two-character language code for the
54
 
            language.  If the language manager already knows about this code,
55
 
            the old language binding is lost.
56
 
        :type code: string
57
 
        :param charset: The character set that the language uses,
58
 
            e.g. 'us-ascii', 'iso-8859-1', or 'utf-8'
59
 
        :type charset: string
60
 
        :param description: The English description of the language,
61
 
            e.g. 'English' or 'French'.
62
 
        :type description: string
63
 
        :return: The language object just added.
64
 
        :rtype: ILanguage
65
 
        """
66
 
 
67
 
    codes = Attribute('An iterator over all known codes.')
68
 
 
69
 
    languages = Attribute('An iterator of all the languages.')
70
 
 
71
 
    def __getitem__(code):
72
 
        """Return the language associated with the language code.
73
 
 
74
 
        :param code: The 2-letter language code.
75
 
        :type code: string
76
 
        :return: The language instance.
77
 
        :rtype: `ILanguage`
78
 
        :raises KeyError: if code is not associated with a known language.
79
 
        """
80
 
 
81
 
    def get(code, default=None):
82
 
        """Return the language associated with the language code.
83
 
 
84
 
        :param code: The 2-letter language code.
85
 
        :type code: string
86
 
        :param default: The value to return if the code is not known.
87
 
        :type default: anything
88
 
        :return: The language instance or `default`.
89
 
        :rtype: `ILanguage` or `default`
90
 
        """
91
 
 
92
 
    def __contains__(code):
93
 
        """True if the language code is known.
94
 
 
95
 
        :return: A flag indicating whether the language code is known or not.
96
 
        :rtype: bool
97
 
        """
98
 
 
99
 
    def clear():
100
 
        """Remove all language code mappings."""