@@ -9,7 +9,7 @@ \section{\module{gettext} ---
99
1010The \module {gettext} module provides internationalization (I18N) and
1111localization (L10N) services for your Python modules and applications.
12- It supports both the GNU \program {gettext} message catalog API and a
12+ It supports both the GNU \code {gettext} message catalog API and a
1313higher level, class-based API that may be more appropriate for Python
1414files. The interface described below allows you to write your
1515module and application messages in one natural language, and provide a
@@ -30,27 +30,28 @@ \subsection{GNU \program{gettext} API}
3030languages on the fly, you probably want to use the class-based API
3131instead.
3232
33- \begin {funcdesc }{bindtextdomain}{domain, localedir\code {=None }}
33+ \begin {funcdesc }{bindtextdomain}{domain\optional { , localedir}}
3434Bind the \var {domain} to the locale directory
3535\var {localedir}. More concretely, \module {gettext} will look for
36- binary \file {.mo} files for the given domain using the path (on Unix ):
36+ binary \file {.mo} files for the given domain using the path (on \UNIX ):
3737\file {\var {localedir}/\var {language}/LC_MESSAGES/\var {domain}.mo},
3838where \var {languages} is searched for in the environment variables
39- \code {LANGUAGE}, \code {LC_ALL}, \code {LC_MESSAGES}, and \code {LANG}
40- respectively.
41-
42- If \var {localedir} is \code {None}, then the current binding for
43- \var {domain} is returned\footnote {The default locale directory is system
44- dependent; e.g. on standard RedHat Linux it is
45- \file {/usr/share/locale}, but on Solaris it is
46- \file {/usr/lib/locale}. The \module {gettext} module does not try to
47- support these system dependent defaults; instead its default is
48- \file {\code {sys.prefix}/share/locale}. For this reason, it is always
49- best to call \code {gettext.bindtextdomain()} with an explicit absolute
50- path at the start of your application.}.
39+ \envvar {LANGUAGE}, \envvar {LC_ALL}, \envvar {LC_MESSAGES}, and
40+ \envvar {LANG} respectively.
41+
42+ If \var {localedir} is omitted or \code {None}, then the current binding
43+ for \var {domain} is returned.\footnote {
44+ The default locale directory is system dependent; e.g.\ on
45+ RedHat Linux it is \file {/usr/share/locale}, but on Solaris it
46+ is \file {/usr/lib/locale}. The \module {gettext} module does
47+ not try to support these system dependent defaults; instead
48+ its default is \file {\code {sys.prefix}/share/locale}. For
49+ this reason, it is always best to call
50+ \function {bindtextdomain()} with an explicit absolute path at
51+ the start of your application.}
5152\end {funcdesc }
5253
53- \begin {funcdesc }{textdomain}{domain \code {=None }}
54+ \begin {funcdesc }{textdomain}{\optional {domain }}
5455Change or query the current global domain. If \var {domain} is
5556\code {None}, then the current global domain is returned, otherwise the
5657global domain is set to \var {domain}, which is returned.
@@ -94,18 +95,18 @@ \subsection{Class-based API}
9495Translations instances can also install themselves in the built-in
9596namespace as the function \function {_()}.
9697
97- \begin {funcdesc }{find}{domain, localedir\code {=None} , languages\code {=None }}
98+ \begin {funcdesc }{find}{domain\optional { , localedir\optional { , languages} }}
9899This function implements the standard \file {.mo} file search
99100algorithm. It takes a \var {domain}, identical to what
100101\function {textdomain()} takes, and optionally a \var {localedir} (as in
101102\function {bindtextdomain()}), and a list of languages. All arguments
102103are strings.
103104
104105If \var {localedir} is not given, then the default system locale
105- directory is used\footnote {See the footnote for
106- \function {bindtextdomain()} above.}. If \var {languages} is not given,
107- then the following environment variables are searched: \code {LANGUAGE},
108- \code {LC_ALL}, \code {LC_MESSAGES}, and \code {LANG}. The first one
106+ directory is used. \footnote {See the footnote for
107+ \function {bindtextdomain()} above.} If \var {languages} is not given,
108+ then the following environment variables are searched: \envvar {LANGUAGE},
109+ \envvar {LC_ALL}, \envvar {LC_MESSAGES}, and \envvar {LANG}. The first one
109110returning a non-empty value is used for the \var {languages} variable.
110111The environment variables can contain a colon separated list of
111112languages, which will be split.
@@ -120,8 +121,8 @@ \subsection{Class-based API}
120121If no such file is found, then \code {None} is returned.
121122\end {funcdesc }
122123
123- \begin {funcdesc }{translation}{domain, localedir\code {=None} ,
124- languages\code {=None} , class_\code {=None }}
124+ \begin {funcdesc }{translation}{domain\optional { , localedir\optional { ,
125+ languages\optional { , class_}} }}
125126Return a \class {Translations} instance based on the \var {domain},
126127\var {localedir}, and \var {languages}, which are first passed to
127128\function {find()} to get the
@@ -133,7 +134,7 @@ \subsection{Class-based API}
133134function raises \exception {IOError}.
134135\end {funcdesc }
135136
136- \begin {funcdesc }{install}{domain, localedir\code {=None} , unicode\code {=0 }}
137+ \begin {funcdesc }{install}{domain\optional { , localedir\optional { , unicode} }}
137138This installs the function \function {_} in Python's builtin namespace,
138139based on \var {domain}, and \var {localedir} which are passed to the
139140function \function {translation()}. The \var {unicode} flag is passed to
@@ -160,7 +161,7 @@ \subsubsection{The \class{NullTranslations} class}
160161to write your own specialized translation classes. Here are the
161162methods of \class {NullTranslations}:
162163
163- \begin {methoddesc }[NullTranslations]{__init__}{fp \code {=None }}
164+ \begin {methoddesc }[NullTranslations]{__init__}{\optional {fp }}
164165Takes an optional file object \var {fp}, which is ignored by the base
165166class. Initializes `` protected'' instance variables \var {_info} and
166167\var {_charset} which are set by derived classes. It then calls
@@ -184,18 +185,18 @@ \subsubsection{The \class{NullTranslations} class}
184185\end {methoddesc }
185186
186187\begin {methoddesc }[NullTranslations]{info}{}
187- Return the `` protected'' \var {_info} variable.
188+ Return the `` protected'' \member {_info} variable.
188189\end {methoddesc }
189190
190191\begin {methoddesc }[NullTranslations]{charset}{}
191- Return the `` protected'' \var {_charset} variable.
192+ Return the `` protected'' \member {_charset} variable.
192193\end {methoddesc }
193194
194- \begin {methoddesc }[NullTranslations]{install}{unicode \code {=0 }}
195+ \begin {methoddesc }[NullTranslations]{install}{\optional {unicode }}
195196If the \var {unicode} flag is false, this method installs
196- \code {self.gettext} into the built-in namespace, binding it to
197- \function {_}. If \var {unicode} is true, it binds \code {self.ugettext}
198- instead.
197+ \method {self.gettext() } into the built-in namespace, binding it to
198+ \samp {_}. If \var {unicode} is true, it binds \method {self.ugettext() }
199+ instead. By default, \var {unicode} is false.
199200
200201Note that this is only one way, albeit the most convenient way, to
201202make the \function {_} function available to your application. Because it
@@ -223,20 +224,20 @@ \subsubsection{The \class{GNUTranslations} class}
223224
224225It also parses optional meta-data out of the translation catalog. It
225226is convention with GNU \program {gettext} to include meta-data as the
226- translation for the empty string. This meta-data is in RFC822 -style
227- \code {key: value} pairs. If the key \code {Content-Type: } is found,
227+ translation for the empty string. This meta-data is in \rfc {822} -style
228+ \code {key: value} pairs. If the key \code {Content-Type} is found,
228229then the \code {charset} property is used to initialize the
229- `` protected'' \code {_charset} instance variable. The entire set of
230+ `` protected'' \member {_charset} instance variable. The entire set of
230231key/value pairs are placed into a dictionary and set as the
231- `` protected'' \code {_info} instance variable.
232+ `` protected'' \member {_info} instance variable.
232233
233234If the \file {.mo} file's magic number is invalid, or if other problems
234235occur while reading the file, instantiating a \class {GNUTranslations} class
235236can raise \exception {IOError}.
236237
237238The other usefully overridden method is \method {ugettext()}, which
238239returns a Unicode string by passing both the translated message string
239- and the value of the `` protected'' \code {_charset} variable to the
240+ and the value of the `` protected'' \member {_charset} variable to the
240241builtin \function {unicode()} function.
241242
242243\subsubsection {Solaris \file {.mo} file support }
@@ -297,12 +298,12 @@ \subsection{Internationalizing your programs and modules}
297298fp.close()
298299\end {verbatim }
299300
300- In this example, the string `` \code {writing a log message} '' is marked as
301- a candidate for translation, while the strings `` \code {mylog.txt} '' and
302- `` \code {w} '' are not.
301+ In this example, the string \code {' writing a log message'} is marked as
302+ a candidate for translation, while the strings \code {' mylog.txt'} and
303+ \code {'w'} are not.
303304
304- The GNU \program {gettext} package provides a tool, called
305- \program {xgettext}, that scans C and C++ source code looking for these
305+ The GNU \code {gettext} package provides a tool, called
306+ \program {xgettext}, that scans C and \Cpp {} source code looking for these
306307specially marked strings. \program {xgettext} generates what are
307308called \file {.pot} files, essentially structured human readable files
308309which contain every marked string in the source code. These
@@ -312,10 +313,11 @@ \subsection{Internationalizing your programs and modules}
312313For I18N Python programs however, \program {xgettext} won't work; it
313314doesn't understand the myriad of string types support by Python. The
314315standard Python distribution provides a tool called
315- \program {pygettext} that does though (found in the \file {Tools/i18n}
316- directory)\footnote {Fran\c cois Pinard has written a program called
316+ \program {pygettext} that does though (found in the \file {Tools/i18n/ }
317+ directory). \footnote {Fran\c cois Pinard has written a program called
317318\program {xpot} which does a similar job. It is distributed separately
318- from the Python distribution.}. This is a command line script that
319+ from the Python distribution.
320+ } This is a command line script that
319321supports a similar interface as \program {xgettext}; see its
320322documentation for details. Once you've used \program {pygettext} to
321323create your \file {.pot} files, you can use the standard GNU
@@ -330,13 +332,12 @@ \subsubsection{Localizing your module}
330332
331333If you are localizing your module, you must take care not to make
332334global changes, e.g. to the built-in namespace. You should not use
333- the GNU \program {gettext} API but instead the class-based API.
335+ the GNU \code {gettext} API but instead the class-based API.
334336
335337Let's say your module is called `` spam'' and the module's various
336338natural language translation \file {.mo} files reside in
337- \file {/usr/share/locale} in GNU
338- \program {gettext} format. Here's what you would put at the top of
339- your module:
339+ \file {/usr/share/locale} in GNU \program {gettext} format. Here's what
340+ you would put at the top of your module:
340341
341342\begin {verbatim }
342343import gettext
@@ -369,7 +370,7 @@ \subsubsection{Localizing your application}
369370gettext.install('myapplication')
370371\end {verbatim }
371372
372- If you need to set the locale directory or the \code {unicode} flag,
373+ If you need to set the locale directory or the \var {unicode} flag,
373374you can pass these into the \function {install()} function:
374375
375376\begin {verbatim }
@@ -444,7 +445,7 @@ \subsubsection{Deferred translations}
444445This works because the dummy definition of \function {_()} simply returns
445446the string unchanged. And this dummy definition will temporarily
446447override any definition of \function {_()} in the built-in namespace
447- (until the \code {del} command).
448+ (until the \keyword {del} command).
448449Take care, though if you have a previous definition of \function {_} in
449450the local namespace.
450451
@@ -470,10 +471,10 @@ \subsubsection{Deferred translations}
470471\end {verbatim }
471472
472473In this case, you are marking translatable strings with the function
473- \function {N_()}\footnote {The choice of \function {N_()} here is totally
474+ \function {N_()}, \footnote {The choice of \function {N_()} here is totally
474475arbitrary; it could have just as easily been
475- \function {MarkThisStringForTranslation()}.},
476- which won't conflict with any definition of
476+ \function {MarkThisStringForTranslation()}.
477+ } which won't conflict with any definition of
477478\function {_()}. However, you will need to teach your message extraction
478479program to look for translatable strings marked with \function {N_()}.
479480\program {pygettext} and \program {xpot} both support this through the
@@ -488,7 +489,7 @@ \subsection{Acknowledgements}
488489\begin {itemize }
489490 \item Peter Funk
490491 \item James Henstridge
491- \item Marc-Andre Lemburg
492+ \item Marc-Andr \' e Lemburg
492493 \item Martin von L\" owis
493494 \item Fran\c cois Pinard
494495 \item Barry Warsaw
0 commit comments