Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d576e9d

Browse files
committed
Markup revisions. Nothing was actually required to be able to format it,
but many conventions were broken.
1 parent 64dab46 commit d576e9d

1 file changed

Lines changed: 55 additions & 54 deletions

File tree

Doc/lib/libgettext.tex

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ \section{\module{gettext} ---
99

1010
The \module{gettext} module provides internationalization (I18N) and
1111
localization (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
1313
higher level, class-based API that may be more appropriate for Python
1414
files. The interface described below allows you to write your
1515
module and application messages in one natural language, and provide a
@@ -30,27 +30,28 @@ \subsection{GNU \program{gettext} API}
3030
languages on the fly, you probably want to use the class-based API
3131
instead.
3232

33-
\begin{funcdesc}{bindtextdomain}{domain, localedir\code{=None}}
33+
\begin{funcdesc}{bindtextdomain}{domain\optional{, localedir}}
3434
Bind 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},
3838
where \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}}
5455
Change or query the current global domain. If \var{domain} is
5556
\code{None}, then the current global domain is returned, otherwise the
5657
global domain is set to \var{domain}, which is returned.
@@ -94,18 +95,18 @@ \subsection{Class-based API}
9495
Translations instances can also install themselves in the built-in
9596
namespace 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}}}
9899
This function implements the standard \file{.mo} file search
99100
algorithm. 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
102103
are strings.
103104

104105
If \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
109110
returning a non-empty value is used for the \var{languages} variable.
110111
The environment variables can contain a colon separated list of
111112
languages, which will be split.
@@ -120,8 +121,8 @@ \subsection{Class-based API}
120121
If 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_}}}}
125126
Return 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}
133134
function 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}}}
137138
This installs the function \function{_} in Python's builtin namespace,
138139
based on \var{domain}, and \var{localedir} which are passed to the
139140
function \function{translation()}. The \var{unicode} flag is passed to
@@ -160,7 +161,7 @@ \subsubsection{The \class{NullTranslations} class}
160161
to write your own specialized translation classes. Here are the
161162
methods of \class{NullTranslations}:
162163

163-
\begin{methoddesc}[NullTranslations]{__init__}{fp\code{=None}}
164+
\begin{methoddesc}[NullTranslations]{__init__}{\optional{fp}}
164165
Takes an optional file object \var{fp}, which is ignored by the base
165166
class. 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}}
195196
If 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

200201
Note that this is only one way, albeit the most convenient way, to
201202
make the \function{_} function available to your application. Because it
@@ -223,20 +224,20 @@ \subsubsection{The \class{GNUTranslations} class}
223224

224225
It also parses optional meta-data out of the translation catalog. It
225226
is 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,
228229
then 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
230231
key/value pairs are placed into a dictionary and set as the
231-
``protected'' \code{_info} instance variable.
232+
``protected'' \member{_info} instance variable.
232233

233234
If the \file{.mo} file's magic number is invalid, or if other problems
234235
occur while reading the file, instantiating a \class{GNUTranslations} class
235236
can raise \exception{IOError}.
236237

237238
The other usefully overridden method is \method{ugettext()}, which
238239
returns 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
240241
builtin \function{unicode()} function.
241242

242243
\subsubsection{Solaris \file{.mo} file support}
@@ -297,12 +298,12 @@ \subsection{Internationalizing your programs and modules}
297298
fp.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
306307
specially marked strings. \program{xgettext} generates what are
307308
called \file{.pot} files, essentially structured human readable files
308309
which contain every marked string in the source code. These
@@ -312,10 +313,11 @@ \subsection{Internationalizing your programs and modules}
312313
For I18N Python programs however, \program{xgettext} won't work; it
313314
doesn't understand the myriad of string types support by Python. The
314315
standard 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
319321
supports a similar interface as \program{xgettext}; see its
320322
documentation for details. Once you've used \program{pygettext} to
321323
create your \file{.pot} files, you can use the standard GNU
@@ -330,13 +332,12 @@ \subsubsection{Localizing your module}
330332

331333
If you are localizing your module, you must take care not to make
332334
global 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

335337
Let's say your module is called ``spam'' and the module's various
336338
natural 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}
342343
import gettext
@@ -369,7 +370,7 @@ \subsubsection{Localizing your application}
369370
gettext.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,
373374
you can pass these into the \function{install()} function:
374375

375376
\begin{verbatim}
@@ -444,7 +445,7 @@ \subsubsection{Deferred translations}
444445
This works because the dummy definition of \function{_()} simply returns
445446
the string unchanged. And this dummy definition will temporarily
446447
override any definition of \function{_()} in the built-in namespace
447-
(until the \code{del} command).
448+
(until the \keyword{del} command).
448449
Take care, though if you have a previous definition of \function{_} in
449450
the local namespace.
450451

@@ -470,10 +471,10 @@ \subsubsection{Deferred translations}
470471
\end{verbatim}
471472

472473
In 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
474475
arbitrary; 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
478479
program 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

Comments
 (0)