Debian Codegraph @

docs/howto/i18n.rst

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