1
# Copyright (C) 2007-2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
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)
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
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/>.
18
"""Interfaces for managing languages."""
20
from __future__ import absolute_import, unicode_literals
29
from zope.interface import Interface, Attribute
33
class ILanguage(Interface):
34
"""The representation of a language."""
36
code = Attribute('The 2-character language code.')
38
charset = Attribute('The character set or encoding for this language.')
40
description = Attribute("The language's description.")
44
class ILanguageManager(Interface):
45
"""A language manager.
47
Current, disabling languages is not supported.
50
def add(code, charset, description):
51
"""Teach the language manager about a language.
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.
57
:param charset: The character set that the language uses,
58
e.g. 'us-ascii', 'iso-8859-1', or 'utf-8'
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.
67
codes = Attribute('An iterator over all known codes.')
69
languages = Attribute('An iterator of all the languages.')
71
def __getitem__(code):
72
"""Return the language associated with the language code.
74
:param code: The 2-letter language code.
76
:return: The language instance.
78
:raises KeyError: if code is not associated with a known language.
81
def get(code, default=None):
82
"""Return the language associated with the language code.
84
:param code: The 2-letter language code.
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`
92
def __contains__(code):
93
"""True if the language code is known.
95
:return: A flag indicating whether the language code is known or not.
100
"""Remove all language code mappings."""