summaryrefslogtreecommitdiff
path: root/src/mailman/docs/languages.txt
blob: 77b51cbeb052455847121830a9c66f62b4f8e51a (plain)
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
Languages
=========

Mailman is multilingual.  A language manager handles the known set of
languages at run time, as well as enabling those languages for use in a
running Mailman instance.

    >>> from mailman.interfaces.languages import ILanguageManager
    >>> from mailman.languages.manager import LanguageManager
    >>> from zope.interface.verify import verifyObject
    >>> mgr = LanguageManager()
    >>> verifyObject(ILanguageManager, mgr)
    True

A language manager keeps track of the languages it knows about.

    >>> list(mgr.codes)
    []
    >>> list(mgr.languages)
    []
    

Adding languages
----------------

Adding a new language requires three pieces of information, the 2-character
language code, the English description of the language, and the character set
used by the language.

    >>> mgr.add('en', 'us-ascii', 'English')
    >>> mgr.add('it', 'iso-8859-1', 'Italian')

And you can get information for all known languages.

    >>> print mgr['en'].description
    English
    >>> print mgr['en'].charset
    us-ascii
    >>> print mgr['it'].description
    Italian
    >>> print mgr['it'].charset
    iso-8859-1


Other iterations
----------------

You can iterate over all the known language codes.

    >>> mgr.add('pl', 'iso-8859-2', 'Polish')
    >>> sorted(mgr.codes)
    [u'en', u'it', u'pl']

You can iterate over all the known languages.

    >>> from operator import attrgetter
    >>> languages = sorted((language for language in mgr.languages),
    ...                    key=attrgetter('code'))
    >>> for language in languages:
    ...     print language.code, language.charset, language.description
    en us-ascii English
    it iso-8859-1 Italian
    pl iso-8859-2 Polish

You can ask whether a particular language code is known.

    >>> 'it' in mgr
    True
    >>> 'xx' in mgr
    False

You can get a particular language by its code.

    >>> print mgr['it'].description
    Italian
    >>> print mgr['xx'].code
    Traceback (most recent call last):
    ...
    KeyError: u'xx'
    >>> print mgr.get('it').description
    Italian
    >>> print mgr.get('xx')
    None
    >>> print mgr.get('xx', 'missing')
    missing