22Roundup Internationalization Notes
33==================================
44
5- :Version: $Revision: 1.7 $
5+ :Version: $Revision: 1.8 $
66
7- FIXME: add introduction - what's l10n, i18n, po, mo, pot, gettext...
7+ Overview
8+ --------
89
9- Used Tools
10- ----------
10+ How stuff works:
1111
12- We use ``xpot`` utility from Francois Pinard free `PO utilities`_
13- to build message template file . ``pygettext`` utility included
14- with Python distribution is not used because it has several limitations:
12+ 1. Strings that may require translation (messages in human language)
13+ are marked in the source code . This step is discussed in
14+ `Marking Strings for Translation`_ section.
1515
16- - no way to mark strings translated elsewhere
17- - does not detect translation done by an object method
18- - source references put in the comments are not recognized
19- by translation software.
16+ 2. These strings are all extracted into Message Template File
17+ ``locale/roundup.pot`` (POT file). See `Extracting Translatable
18+ Messages`_ below.
2019
21- Message translation can be done with `emacs`_ "po mode" provided
22- by `PO utilities`_. (als: i didn't try that personally.)
20+ 3. Language teams use POT file to make Message Files for national
21+ languages (PO files). All PO files for Roundup are kept in
22+ the ``locale`` directory. Names of these files are target
23+ locale names, usually just 2-letter language codes. `Translating
24+ Messages`_ section of this document gives useful hints for
25+ message translators.
2326
24- Another tool for message translation (als: one that i use) is `poEdit`_
25- by Vaclav Slavik.
27+ 4. Translated Message Files are compiled into binary form (MO files)
28+ and stored in ``locale`` directory (but not kept in the `Roundup
29+ CVS`_ repository, as they may be easily made from PO files).
30+ See `Compiling Message Catalogs`_ section.
2631
27- .. _PO utilities: http://po-utils.progiciels-bpi.ca/
28- .. _emacs: http://www.gnu.org/software/emacs/
29- .. _poEdit: http://poedit.sourceforge.net/
32+ 5. Roundup installer creates runtime locale structure on the file
33+ system, putting MO files in their appropriate places.
34+
35+ 6. Runtime internationalization (I18N) services use these MO files
36+ to translate program messages into language selected by current
37+ Roundup user. Roundup command line interface uses locale name
38+ set in OS environment variable ``LANGUAGE``, ``LC_ALL``,
39+ ``LC_MESSAGES``, or ``LANG`` (in that order). Roundup Web User
40+ Interface uses language selected by currentluy authenticated user.
41+
42+ Additional details may be found in `GNU gettext`_ and Python `gettext
43+ module`_ documentation.
44+
45+ `Roundup source distribution`_ includes POT and PO files for message
46+ translators, and also pre-built MO files to facilitate installations
47+ from source. `Roundup binary distribution`_ includes MO files only.
48+
49+ .. _GNU gettext:
50+
51+ GNU gettext package
52+ -------------------
53+
54+ This document is full of references to `GNU`_ `gettext package`_.
55+ GNU gettext is a "must have" for nearly all steps of internationalizing
56+ any program, and it's manual is definetely a recommended reading
57+ for people involved in I18N.
58+
59+ There are GNU gettext ports to all major OS platforms.
60+ Windows binaries are available from ``GNU mirror sites``.
61+
62+ Roundup does not use GNU gettext at runtime, but it's tools
63+ are used for `extracting translatable messages`_, `compiling
64+ message catalogs`_ and, optionally, for `translating messages`_.
65+
66+ Note that ``gettext`` package in some OS distributions (e.g.
67+ `FreeBSD`_) means just runtime libraries. Development tools
68+ are usually distributed in separate package named ``gettext-devel``.
3069
3170Marking Strings for Translation
3271-------------------------------
3372
3473Strings that need translation must be marked in the source code.
74+ Following sections of this chapter explain how this is done in
75+ different cases.
76+
77+ Current status of the string marks in Roundup core files is shown
78+ in `I18 Status`_ section at the end of this document.
79+
80+ If translatable string is used as a format string, it is recommended
81+ to always use named format specifiers::
82+
83+ _('Index of %(classname)s') % locals()
84+
85+ This helps translators to better understand the context of the
86+ message and, in Python, remove format specifier altogether (which
87+ is sometimes useful, especially in singular cases of `Plural Forms`_).
88+ When there is more than one format specifier in the translatable
89+ format string, named format specifiers *must* be used almost always,
90+ because translation may require different order of items.
91+
92+ It is better to *not* mark for translation strings that are not
93+ locale-dependent, as this makes it more difficult to keep track
94+ of translation completeness. For example: following string in
95+ ``index()`` method of the request handler in ``roundup_server``
96+ script::
97+
98+ </ol></body></html>
99+
100+ has no human readable parts at all, and needs no translations.
101+ These strings are left untranslated in PO files, and are reported
102+ as such by PO status checkers (e.g. ``msgfmt --statistics``).
35103
36104Command Line Interfaces
37105~~~~~~~~~~~~~~~~~~~~~~~
@@ -47,20 +115,18 @@ For these interfaces, Python ``gettext`` engine must be initialized
47115to use Roundup message catalogs. This is normally done by including
48116the following line in the module imports::
49117
50- from i18n import _
118+ from i18n import _, ngettext
51119
52120Simple translations are automatically marked by calls to builtin
53121message translation function ``_()``::
54122
55123 print _("This message is translated")
56124
57- *(not tested)* Translations for messages whose grammatical depends
58- on a number must be done by ``ngettext()`` function::
125+ Translations for messages whose grammatical depends on a number
126+ must be done by ``ngettext()`` function::
59127
60128 print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked)
61129
62- *Discussion:* make ``i18n._()`` with the same interface as in ``config._()``?
63-
64130User Interfaces
65131~~~~~~~~~~~~~~~
66132
@@ -69,17 +135,19 @@ User Interfaces
69135This includes Mail Gateway and Web User Interfaces, where translation
70136depends on the language of current Roundup User. These translations
71137will be done by the tracker configuration object. Translatable strings
72- will be automatically marked by calls to the ``_()`` method of that
73- object::
138+ will be automatically marked by calls to the ``_()`` and ``ngettext()``
139+ methods of that object::
74140
75141 self.config._("This message is translated")
76- self.config._("Nuked %i file", "Nuked %i files", number_of_files_nuked)
142+ self.config.ngettext("Nuked %i file", "Nuked %i files",
143+ number_of_files_nuked)
77144
78145Deferred Translations
79146~~~~~~~~~~~~~~~~~~~~~
80147
81148Sometimes translatable strings appear in the source code in untranslated
82- form and must be translated elsewhere. Example::
149+ form [#note_admin.py]_ and must be translated elsewhere.
150+ Example::
83151
84152 for meal in ("spam", "egg", "beacon"):
85153 print _(meal)
@@ -97,23 +165,39 @@ types of string quotes::
97165 multiline string"""
98166 )
99167
100- Building Message Catalog Template
101- ---------------------------------
168+ .. [#note_admin.py] In current Roundup sources, this feature is
169+ extensively used in the ``admin`` module using method docstrings
170+ as help messages.
171+
172+ Extracting Translatable Messages
173+ --------------------------------
102174
103- Message catalog template ``roundup.pot`` is kept in `Roundup CVS`_
104- and distributed with `Roundup Source`_. If you wish to rebuild
105- the template yourself, you will need ``xpot`` utility by Francois
106- Pinard, included in `PO utilities`_ distribution.
175+ The most common tool for message extraction is ``xgettext`` utility
176+ from `GNU gettext package`_. Unfortunately, this utility has no means
177+ of `Deferred Translations`_ in Python sources.
178+ There is ``xpot`` tool from Francois Pinard free `PO utilities`_
179+ that allows to mark strings for `deferred translations`_, but
180+ it does not handle `plural forms`_.
181+ Roundup overcomes these limitations by using both of these utilities.
182+ This means that you need both `GNU gettext`_ tools and `PO utilities`_
183+ to build the Message Template File yourself.
107184
108- To rebuild the template file, just run ``gmake`` (or ``make``, if you
109- are on a `GNU`_ system like `linux`_ or `cygwin`_) in the 'locale'
110- directory.
185+ Latest Message Template File is kept in `Roundup CVS`_ and distributed
186+ with `Roundup Source`_.
187+ If you wish to rebuild the template yourself, make sure that you have
188+ both ``xpot`` and ``xgettext`` installed and just run ``gmake`` (or
189+ ``make``, if you are on a `GNU`_ system like `linux`_ or `cygwin`_)
190+ in the ``locale`` directory.
111191
112- .. Roundup CVS: http://sourceforge.net/cvs/?group_id=31577
113- .. Roundup Source: http://sourceforge.net/project/showfiles.php?group_id=31577
114- .. GNU: http://www.gnu.org/
115- .. linux: http://www.linux.org/
116- .. cygwin: http://www.cygwin.com/
192+ Translating Messages
193+ --------------------
194+
195+ FIXME!
196+
197+ Compiling Message Catalogs
198+ --------------------------
199+
200+ FIXME!
117201
118202I18 Status
119203----------
@@ -200,3 +284,24 @@ test/test_schema.py
200284test/test_templating.py
201285test/unittest.py
202286
287+ .. External hyperlink targets
288+
289+ .. _cygwin: http://www.cygwin.com/
290+ .. _emacs: http://www.gnu.org/software/emacs/
291+ .. _gettext package: http://www.gnu.org/software/gettext/
292+ .. _gettext module: http://docs.python.org/lib/module-gettext.html
293+ .. _GNU: http://www.gnu.org/
294+ .. _GNU mirror sites: http://www.gnu.org/prep/ftp.html
295+ .. _FreeBSD: http://www.freebsd.org/
296+ .. _linux: http://www.linux.org/
297+ .. _Plural Forms:
298+ http://www.gnu.org/software/gettext/manual/html_node/gettext_150.html
299+ .. _po filetype plugin:
300+ http://vim.sourceforge.net/scripts/script.php?script_id=695
301+ .. _PO utilities: http://po-utils.progiciels-bpi.ca/
302+ .. _poEdit: http://poedit.sourceforge.net/
303+ .. _Roundup CVS: http://sourceforge.net/cvs/?group_id=31577
304+ .. _Roundup Source:
305+ .. _Roundup source distribution:
306+ .. _Roundup binary distribution:
307+ http://sourceforge.net/project/showfiles.php?group_id=31577
0 commit comments