1313
1414The :mod: `gettext ` module provides internationalization (I18N) and localization
1515(L10N) services for your Python modules and applications. It supports both the
16- GNU `` gettext ` ` message catalog API and a higher level, class-based API that may
16+ GNU :program: ` gettext ` message catalog API and a higher level, class-based API that may
1717be more appropriate for Python files. The interface described below allows you
1818to write your module and application messages in one natural language, and
1919provide a catalog of translated messages for running under different natural
@@ -38,7 +38,7 @@ class-based API instead.
3838
3939 Bind the *domain * to the locale directory *localedir *. More concretely,
4040 :mod: `gettext ` will look for binary :file: `.mo ` files for the given domain using
41-  the path (on Unix): :file: `localedir/ language/LC_MESSAGES/domain.mo `, where
41+  the path (on Unix): :file: `{ localedir } / { language } /LC_MESSAGES/{ domain } .mo `, where
4242 *languages * is searched for in the environment variables :envvar: `LANGUAGE `,
4343 :envvar: `LC_ALL `, :envvar: `LC_MESSAGES `, and :envvar: `LANG ` respectively.
4444
@@ -138,17 +138,16 @@ Class-based API
138138The class-based API of the :mod: `gettext ` module gives you more flexibility and
139139greater convenience than the GNU :program: `gettext ` API. It is the recommended
140140way of localizing your Python applications and modules. :mod: `!gettext ` defines
141- a "translations" class which implements the parsing of GNU :file: `.mo ` format
142- files, and has methods for returning strings. Instances of this "translations"
143- class can also install themselves in the built-in namespace as the function
144- :func: `_ `.
141+ a :class: `GNUTranslations ` class which implements the parsing of GNU :file: `.mo ` format
142+ files, and has methods for returning strings. Instances of this class can also
143+ install themselves in the built-in namespace as the function :func: `_ `.
145144
146145
147146.. function :: find(domain, localedir=None, languages=None, all=False) 
148147
149148 This function implements the standard :file: `.mo ` file search algorithm. It
150149 takes a *domain *, identical to what :func: `textdomain ` takes. Optional
151-  *localedir * is as in :func: `bindtextdomain `   Optional *languages * is a list of
150+  *localedir * is as in :func: `bindtextdomain `.  Optional *languages * is a list of
152151 strings, where each string is a language code.
153152
154153 If *localedir * is not given, then the default system locale directory is used.
@@ -172,10 +171,10 @@ class can also install themselves in the built-in namespace as the function
172171
173172.. function :: translation(domain, localedir=None, languages=None, class_=None, fallback=False, codeset=None) 
174173
175-  Return a :class: `Translations ` instance based on the *domain *, *localedir *,
174+  Return a :class: `* Translations ` instance based on the *domain *, *localedir *,
176175 and *languages *, which are first passed to :func: `find ` to get a list of the
177176 associated :file: `.mo ` file paths. Instances with identical :file: `.mo ` file
178-  names are cached. The actual class instantiated is either  *class_ * if
177+  names are cached. The actual class instantiated is *class_ * if
179178 provided, otherwise :class: `GNUTranslations `. The class's constructor must
180179 take a single :term: `file object ` argument. If provided, *codeset * will change
181180 the charset used to encode translated strings in the
@@ -241,7 +240,7 @@ are the methods of :class:`!NullTranslations`:
241240
242241 .. method :: _parse(fp) 
243242
244-  No-op'd  in the base class, this method takes file object *fp *, and reads
243+  No-op in the base class, this method takes file object *fp *, and reads
245244 the data from the file, initializing its message catalog. If you have an
246245 unsupported message catalog file format, you should override this method
247246 to parse your format.
@@ -285,7 +284,8 @@ are the methods of :class:`!NullTranslations`:
285284
286285 .. method :: info() 
287286
288-  Return the "protected" :attr: `_info ` variable.
287+  Return the "protected" :attr: `_info ` variable, a dictionary containing
288+  the metadata found in the message catalog file.
289289
290290
291291 .. method :: charset() 
@@ -340,15 +340,15 @@ The :mod:`gettext` module provides one additional class derived from
340340:meth: `_parse ` to enable reading GNU :program: `gettext ` format :file: `.mo ` files
341341in both big-endian and little-endian format.
342342
343- :class: `GNUTranslations ` parses optional meta-data  out of the translation
344- catalog.   It is convention with GNU :program: `gettext ` to include meta-data  as
345- the translation for the empty string.   This meta-data  is in :rfc: `822 `\  -style
343+ :class: `GNUTranslations ` parses optional metadata  out of the translation
344+ catalog. It is convention with GNU :program: `gettext ` to include metadata  as
345+ the translation for the empty string. This metadata  is in :rfc: `822 `\  -style
346346``key: value `` pairs, and should contain the ``Project-Id-Version `` key. If the
347347key ``Content-Type `` is found, then the ``charset `` property is used to
348348initialize the "protected" :attr: `_charset ` instance variable, defaulting to
349349``None `` if not found. If the charset encoding is specified, then all message
350350ids and message strings read from the catalog are converted to Unicode using
351- this encoding, else ASCII encoding  is assumed.
351+ this encoding, else ASCII is assumed.
352352
353353Since message ids are read as Unicode strings too, all :meth: `*gettext ` methods
354354will assume message ids as Unicode strings, not byte strings.
@@ -452,7 +452,7 @@ take the following steps:
452452
453453#. run a suite of tools over your marked files to generate raw messages catalogs
454454
455- #. create language  specific translations of the message catalogs
455+ #. create language- specific translations of the message catalogs
456456
457457#. use the :mod: `gettext ` module so that message strings are properly translated
458458
@@ -462,9 +462,8 @@ it in ``_('...')`` --- that is, a call to the function :func:`_`. For example::
462462
463463 filename = 'mylog.txt' 
464464 message = _('writing a log message') 
465-  fp = open(filename, 'w') 
466-  fp.write(message) 
467-  fp.close() 
465+  with open(filename, 'w') as fp: 
466+  fp.write(message) 
468467
469468In this example, the string ``'writing a log message' `` is marked as a candidate
470469for translation, while the strings ``'mylog.txt' `` and ``'w' `` are not.
@@ -515,7 +514,7 @@ Localizing your module
515514^^^^^^^^^^^^^^^^^^^^^^ 
516515
517516If you are localizing your module, you must take care not to make global
518- changes, e.g. to the built-in namespace.   You should not use the GNU `` gettext ` `
517+ changes, e.g. to the built-in namespace. You should not use the GNU :program: ` gettext `
519518API but instead the class-based API.
520519
521520Let's say your module is called "spam" and the module's various natural language
@@ -669,8 +668,9 @@ implementations, and valuable experience to the creation of this module:
669668.. [# ] The default locale directory is system dependent; for example, on RedHat Linux 
670669 it is :file: `/usr/share/locale `, but on Solaris it is :file: `/usr/lib/locale `. 
671670 The :mod: `gettext ` module does not try to support these system dependent 
672-  defaults; instead its default is :file: `sys.prefix/share/locale `. For this 
673-  reason, it is always best to call :func: `bindtextdomain ` with an explicit 
674-  absolute path at the start of your application. 
671+  defaults; instead its default is :file: `{ sys.prefix } /share/locale ` (see 
672+  :data: `sys.prefix `). For this reason, it is always best to call 
673+  :func: `bindtextdomain ` with an explicit absolute path at the start of your 
674+  application. 
675675
676676 .. [# ] See the footnote for :func: `bindtextdomain ` above. 
0 commit comments