annotate doc/catalogs.txt @ 8:29f6f9a90f14 trunk

Pull in some supplemental data from the CLDR, for things like the first day of the week.
author cmlenz
date Wed, 30 May 2007 17:39:43 +0000
parents 20896f1e91c6
children 0739bc8e7210
rev   line source
2
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
1 .. -*- mode: rst; encoding: utf-8 -*-
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
2
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
3 =============================
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
4 Working with Message Catalogs
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
5 =============================
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
6
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
7 .. contents:: Contents
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
8 :depth: 2
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
9 .. sectnum::
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
10
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
11
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
12 Introduction
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
13 ============
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
14
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
15 The ``gettext`` translation system enables you to mark any strings used in your
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
16 application as subject to localization, by wrapping them in functions such as
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
17 ``gettext(str)`` and ``ngettext(singular, plural, num)``. For brevity, the
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
18 ``gettext`` function is often aliased to ``_(str)``, so you can write::
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
19
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
20 print _("Hello")
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
21
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
22 instead of just::
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
23
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
24 print "Hello"
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
25
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
26 to make the string "Hello" localizable.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
27
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
28 Message catalogs are collections of translations for such localizable messages
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
29 used in an application. They are commonly stored in PO (Portable Object) and MO
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
30 (Machine Object) files, the formats of which are defined by the GNU `gettext`_
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
31 tools and the GNU `translation project`_.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
32
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
33 .. _`gettext`: http://www.gnu.org/software/gettext/
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
34 .. _`translation project`: http://sourceforge.net/projects/translation
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
35
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
36 The general procedure for building message catalogs looks something like this:
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
37
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
38 * use a tool (such as ``xgettext``) to extract localizable strings from the
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
39 code base and write them to a POT (PO Template) file.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
40 * make a copy of the POT file for a specific locale (for example, "en_US")
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
41 and start translating the messages
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
42 * use a tool such as ``msgfmt`` to compile the locale PO file into an binary
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
43 MO file
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
44 * later, when code changes make it necessary to update the translations, you
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
45 regenerate the POT file and merge the changes into the various
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
46 locale-specific PO files, for example using ``msgmerge``
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
47
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
48 Python provides the `gettext module`_ as part of the standard library, which
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
49 enables applications to work with appropriately generated MO files.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
50
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
51 .. _`gettext module`: http://docs.python.org/lib/module-gettext.html
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
52
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
53 As ``gettext`` provides a solid and well supported foundation for translating
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
54 application messages, Babel does not reinvent the wheel, but rather reuses this
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
55 infrastructure, and makes it easier to build message catalogs for Python
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
56 applications.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
57
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
58
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
59 Message Extraction
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
60 ==================
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
61
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
62 Babel provides functionality similar to that of the ``xgettext`` program,
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
63 except that only extraction from Python source files is built-in, while support
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
64 for other file formats can be added using a simple extension mechanism.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
65
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
66 (TODO: more)
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
67
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
68
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
69 --------------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
70 Writing Extraction Methods
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
71 --------------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
72
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
73 (TODO: write)
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
74
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
75 ---------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
76 ``setup.py`` Commands
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
77 ---------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
78
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
79 (TODO: overview)
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
80
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
81 See `Distutils/Setuptools Integration <setup.html>`_ for more information.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
82
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
83 -------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
84 Command-line script
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
85 -------------------
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
86
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
87 (TODO: overview)
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
88
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
89 See `Command-Line Interface <cmdline.html>`_ for more information.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
90
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
91
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
92 Extended ``Translations`` Class
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
93 ===============================
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
94
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
95 Many web-based applications are composed of a variety of different components
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
96 (possibly using some kind of plugin system), and some of those components may
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
97 provide their own message catalogs that need to be integrated into the larger
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
98 system.
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
99
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
100 To support this usage pattern, Babel provides a ``Translations`` class that is
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
101 derived from the ``GNUTranslations`` class in the ``gettext`` module. This
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
102 class adds a ``merge()`` method that takes another ``Translations`` instance,
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
103 and merges its contents into the catalog::
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
104
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
105 translations = Translations.load('main')
20896f1e91c6 Forgot to check in the doc directory.
cmlenz
parents:
diff changeset
106 translations.merge(Translations.load('plugin1'))
Copyright (C) 2012-2017 Edgewall Software