Debian Codegraph @

test/expensive_benchmarks/docutils_data/docs/howto/i18n.txt

raw
1 ================================
2 Docutils_ Internationalization
3 ================================
4
5 :Author: David Goodger
6 :Contact: [email protected]
7 :Date: $Date$
8 :Revision: $Revision$
9 :Copyright: This document has been placed in the public domain.
10
11
12 .. contents::
13
14
15 This document describes the internationalization facilities of the
16 Docutils_ project. `Introduction to i18n`_ by Tomohiro KUBOTA is a
17 good general reference. "Internationalization" is often abbreviated
18 as "i18n": "i" + 18 letters + "n".
19
20 .. Note::
21
22 The i18n facilities of Docutils should be considered a "first
23 draft". They work so far, but improvements are welcome.
24 Specifically, standard i18n facilities like "gettext" have yet to
25 be explored.
26
27 Docutils is designed to work flexibly with text in multiple languages
28 (one language at a time). Language-specific features are (or should
29 be [#]_) fully parameterized. To enable a new language, two modules
30 have to be added to the project: one for Docutils itself (the
31 `Docutils Language Module`_) and one for the reStructuredText parser
32 (the `reStructuredText Language Module`_). Users may add local language
33 support via a module in the PYTHONPATH root (e.g. the working directory).
34
35 .. [#] If anything in Docutils is insufficiently parameterized, it
36 should be considered a bug. Please report bugs to the Docutils
37 project bug tracker on SourceForge at
38 https://sourceforge.net/p/docutils/bugs/
39
40 .. _Docutils: https://docutils.sourceforge.io/
41 .. _Introduction to i18n:
42 http://www.debian.org/doc/manuals/intro-i18n/
43
44
45 Language Module Names
46 =====================
47
48 Language modules are named using `language tags`_ as defined in
49 `BCP 47`_. [#]_ in lowercase, converting hyphens to underscores [#]_.
50
51 A typical language identifier consists of a 2-letter language code
52 from `ISO 639`_ (3-letter codes can be used if no 2-letter code
53 exists). The language identifier can have an optional subtag,
54 typically for variations based on country (from `ISO 3166`_ 2-letter
55 country codes). If no language identifier is specified, the default
56 is "en" for English. Examples of module names include ``en.py``,
57 ``fr.py``, ``ja.py``, and ``pt_br.py``.
58
59 .. [#] BCP stands for 'Best Current Practice', and is a persistent
60 name for a series of RFCs whose numbers change as they are updated.
61 The latest RFC describing language tag syntax is RFC 5646, Tags for
62 the Identification of Languages, and it obsoletes the older RFCs
63 4646, 3066 and 1766.
64
65 .. [#] Subtags are separated from primary tags by underscores instead
66 of hyphens, to conform to Python naming rules.
67
68 .. _language tags: https://www.w3.org/International/articles/language-tags/
69 .. _BCP 47: https://www.rfc-editor.org/rfc/bcp/bcp47.txt
70 .. _ISO 639: http://www.loc.gov/standards/iso639-2/php/English_list.php
71 .. _ISO 3166: http://www.iso.ch/iso/en/prods-services/iso3166ma/
72 02iso-3166-code-lists/index.html
73
74
75 Docutils Language Module
76 ========================
77
78 Modules in ``docutils/languages`` contain language mappings for
79 markup-independent language-specific features of Docutils. To make a
80 new language module, just copy the ``en.py`` file, rename it with the
81 code for your language (see `Language Module Names`_ above), and
82 translate the terms as described below.
83
84 Each Docutils language module contains three module attributes:
85
86 ``labels``
87 This is a mapping of node class names to language-dependent
88 boilerplate label text. The label text is used by Writer
89 components when they encounter document tree elements whose class
90 names are the mapping keys.
91
92 The entry values (*not* the keys) should be translated to the
93 target language.
94
95 ``bibliographic_fields``
96 This is a mapping of language-dependent field names (converted to
97 lower case) to canonical field names (keys of
98 ``DocInfo.biblio_notes`` in ``docutils.transforms.frontmatter``).
99 It is used when transforming bibliographic fields.
100
101 The keys should be translated to the target language.
102
103 ``author_separators``
104 This is a list of strings used to parse the 'Authors'
105 bibliographic field. They separate individual authors' names, and
106 are tried in order (i.e., earlier items take priority, and the
107 first item that matches wins). The English-language module
108 defines them as ``[';', ',']``; semi-colons can be used to
109 separate names like "Arthur Pewtie, Esq.".
110
111 Most languages won't have to "translate" this list.
112
113
114 reStructuredText Language Module
115 ================================
116
117 Modules in ``docutils/parsers/rst/languages`` contain language
118 mappings for language-specific features of the reStructuredText
119 parser. To make a new language module, just copy the ``en.py`` file,
120 rename it with the code for your language (see `Language Module
121 Names`_ above), and translate the terms as described below.
122
123 Each reStructuredText language module contains two module attributes:
124
125 ``directives``
126 This is a mapping from language-dependent directive names to
127 canonical directive names. The canonical directive names are
128 registered in ``docutils/parsers/rst/directives/__init__.py``, in
129 ``_directive_registry``.
130
131 The keys should be translated to the target language. Synonyms
132 (multiple keys with the same values) are allowed; this is useful
133 for abbreviations.
134
135 ``roles``
136 This is a mapping language-dependent role names to canonical role
137 names for interpreted text. The canonical directive names are
138 registered in ``docutils/parsers/rst/states.py``, in
139 ``Inliner._interpreted_roles`` (this may change).
140
141 The keys should be translated to the target language. Synonyms
142 (multiple keys with the same values) are allowed; this is useful
143 for abbreviations.
144
145
146 Testing the Language Modules
147 ============================
148
149 Whenever a new language module is added or an existing one modified,
150 the unit tests should be run. The test modules can be found in the
151 docutils/test directory from code_ or from the `latest snapshot`_.
152
153 The ``test_language.py`` module can be run as a script. With no
154 arguments, it will test all language modules. With one or more
155 language codes, it will test just those languages. For example::
156
157 $ python test_language.py en
158 ..
159 ----------------------------------------
160 Ran 2 tests in 0.095s
161
162 OK
163
164 Use the "alltests.py" script to run all test modules, exhaustively
165 testing the parser and other parts of the Docutils system.
166
167 .. _code: https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/
168 .. _latest snapshot: https://sourceforge.net/p/docutils/code/HEAD/tarball
169
170
171 Submitting the Language Modules
172 ===============================
173
174 If you do not have repository write access and want to contribute your
175 language modules, feel free to submit them via the `SourceForge patch
176 tracker`__.
177
178 __ https://sourceforge.net/p/docutils/patches/