@@ -58,7 +58,7 @@ class-based API instead.
58
58
59
59
Return the localized translation of *message *, based on the current global
60
60
domain, language, and locale directory. This function is usually aliased as
61
- :func: `_ ` in the local namespace (see examples below).
61
+ :func: `! _ ` in the local namespace (see examples below).
62
62
63
63
64
64
.. function :: dgettext(domain, message)
@@ -98,7 +98,7 @@ class-based API instead.
98
98
.. versionadded :: 3.8
99
99
100
100
101
- Note that GNU :program: `gettext ` also defines a :func: `dcgettext ` method, but
101
+ Note that GNU :program: `gettext ` also defines a :func: `! dcgettext ` method, but
102
102
this was deemed not useful and so it is currently unimplemented.
103
103
104
104
Here's an example of typical usage for this API::
@@ -119,7 +119,7 @@ greater convenience than the GNU :program:`gettext` API. It is the recommended
119
119
way of localizing your Python applications and modules. :mod: `!gettext ` defines
120
120
a :class: `GNUTranslations ` class which implements the parsing of GNU :file: `.mo ` format
121
121
files, and has methods for returning strings. Instances of this class can also
122
- install themselves in the built-in namespace as the function :func: `_ `.
122
+ install themselves in the built-in namespace as the function :func: `! _ `.
123
123
124
124
125
125
.. function :: find(domain, localedir=None, languages=None, all=False)
@@ -150,15 +150,12 @@ install themselves in the built-in namespace as the function :func:`_`.
150
150
151
151
.. function :: translation(domain, localedir=None, languages=None, class_=None, fallback=False)
152
152
153
- Return a :class: ` *Translations ` instance based on the *domain *, *localedir *,
153
+ Return a `` *Translations ` ` instance based on the *domain *, *localedir *,
154
154
and *languages *, which are first passed to :func: `find ` to get a list of the
155
155
associated :file: `.mo ` file paths. Instances with identical :file: `.mo ` file
156
156
names are cached. The actual class instantiated is *class_ * if
157
157
provided, otherwise :class: `GNUTranslations `. The class's constructor must
158
- take a single :term: `file object ` argument. If provided, *codeset * will change
159
- the charset used to encode translated strings in the
160
- :meth: `~NullTranslations.lgettext ` and :meth: `~NullTranslations.lngettext `
161
- methods.
158
+ take a single :term: `file object ` argument.
162
159
163
160
If multiple files are found, later files are used as fallbacks for earlier ones.
164
161
To allow setting the fallback, :func: `copy.copy ` is used to clone each
@@ -177,19 +174,19 @@ install themselves in the built-in namespace as the function :func:`_`.
177
174
178
175
.. function :: install(domain, localedir=None, *, names=None)
179
176
180
- This installs the function :func: `_ ` in Python's builtins namespace, based on
177
+ This installs the function :func: `! _ ` in Python's builtins namespace, based on
181
178
*domain * and *localedir * which are passed to the function :func: `translation `.
182
179
183
180
For the *names * parameter, please see the description of the translation
184
181
object's :meth: `~NullTranslations.install ` method.
185
182
186
183
As seen below, you usually mark the strings in your application that are
187
- candidates for translation, by wrapping them in a call to the :func: `_ `
184
+ candidates for translation, by wrapping them in a call to the :func: `! _ `
188
185
function, like this::
189
186
190
187
print(_('This string will be translated.'))
191
188
192
- For convenience, you want the :func: `_ ` function to be installed in Python's
189
+ For convenience, you want the :func: `! _ ` function to be installed in Python's
193
190
builtins namespace, so it is easily accessible in all modules of your
194
191
application.
195
192
@@ -276,20 +273,20 @@ are the methods of :class:`!NullTranslations`:
276
273
277
274
If the *names * parameter is given, it must be a sequence containing the
278
275
names of functions you want to install in the builtins namespace in
279
- addition to :func: `_ `. Supported names are ``'gettext' ``, ``'ngettext' ``,
280
- ``'pgettext' ``, `` 'npgettext' ``, `` 'lgettext' ``, and ``'lngettext ' ``.
276
+ addition to :func: `! _ `. Supported names are ``'gettext' ``, ``'ngettext' ``,
277
+ ``'pgettext' ``, and ``'npgettext ' ``.
281
278
282
279
Note that this is only one way, albeit the most convenient way, to make
283
- the :func: `_ ` function available to your application. Because it affects
280
+ the :func: `! _ ` function available to your application. Because it affects
284
281
the entire application globally, and specifically the built-in namespace,
285
- localized modules should never install :func: `_ `. Instead, they should use
286
- this code to make :func: `_ ` available to their module::
282
+ localized modules should never install :func: `! _ `. Instead, they should use
283
+ this code to make :func: `! _ ` available to their module::
287
284
288
285
import gettext
289
286
t = gettext.translation('mymodule', ...)
290
287
_ = t.gettext
291
288
292
- This puts :func: `_ ` only in the module's global namespace and so only
289
+ This puts :func: `! _ ` only in the module's global namespace and so only
293
290
affects calls within this module.
294
291
295
292
.. versionchanged :: 3.8
@@ -314,7 +311,7 @@ initialize the "protected" :attr:`_charset` instance variable, defaulting to
314
311
ids and message strings read from the catalog are converted to Unicode using
315
312
this encoding, else ASCII is assumed.
316
313
317
- Since message ids are read as Unicode strings too, all :meth: ` *gettext ` methods
314
+ Since message ids are read as Unicode strings too, all `` *gettext() ` ` methods
318
315
will assume message ids as Unicode strings, not byte strings.
319
316
320
317
The entire set of key/value pairs are placed into a dictionary and set as the
@@ -404,7 +401,7 @@ version has a slightly different API. Its documented usage was::
404
401
_ = cat.gettext
405
402
print(_('hello world'))
406
403
407
- For compatibility with this older module, the function :func: `Catalog ` is an
404
+ For compatibility with this older module, the function :func: `! Catalog ` is an
408
405
alias for the :func: `translation ` function described above.
409
406
410
407
One difference between this module and Henstridge's: his catalog objects
@@ -432,7 +429,7 @@ take the following steps:
432
429
433
430
In order to prepare your code for I18N, you need to look at all the strings in
434
431
your files. Any string that needs to be translated should be marked by wrapping
435
- it in ``_('...') `` --- that is, a call to the function :func: `_ `. For example::
432
+ it in ``_('...') `` --- that is, a call to the function :func: `_ <gettext> `. For example::
436
433
437
434
filename = 'mylog.txt'
438
435
message = _('writing a log message')
@@ -504,7 +501,7 @@ module::
504
501
Localizing your application
505
502
^^^^^^^^^^^^^^^^^^^^^^^^^^^
506
503
507
- If you are localizing your application, you can install the :func: `_ ` function
504
+ If you are localizing your application, you can install the :func: `! _ ` function
508
505
globally into the built-in namespace, usually in the main driver file of your
509
506
application. This will let all your application-specific files just use
510
507
``_('...') `` without having to explicitly install it in each file.
@@ -581,13 +578,13 @@ Here is one way you can handle this situation::
581
578
for a in animals:
582
579
print(_(a))
583
580
584
- This works because the dummy definition of :func: `_ ` simply returns the string
581
+ This works because the dummy definition of :func: `! _ ` simply returns the string
585
582
unchanged. And this dummy definition will temporarily override any definition
586
- of :func: `_ ` in the built-in namespace (until the :keyword: `del ` command). Take
587
- care, though if you have a previous definition of :func: `_ ` in the local
583
+ of :func: `! _ ` in the built-in namespace (until the :keyword: `del ` command). Take
584
+ care, though if you have a previous definition of :func: `! _ ` in the local
588
585
namespace.
589
586
590
- Note that the second use of :func: `_ ` will not identify "a" as being
587
+ Note that the second use of :func: `! _ ` will not identify "a" as being
591
588
translatable to the :program: `gettext ` program, because the parameter
592
589
is not a string literal.
593
590
@@ -606,13 +603,13 @@ Another way to handle this is with the following example::
606
603
print(_(a))
607
604
608
605
In this case, you are marking translatable strings with the function
609
- :func: `N_ `, which won't conflict with any definition of :func: `_ `.
606
+ :func: `! N_ `, which won't conflict with any definition of :func: `! _ `.
610
607
However, you will need to teach your message extraction program to
611
- look for translatable strings marked with :func: `N_ `. :program: `xgettext `,
608
+ look for translatable strings marked with :func: `! N_ `. :program: `xgettext `,
612
609
:program: `pygettext `, ``pybabel extract ``, and :program: `xpot ` all
613
610
support this through the use of the :option: `!-k ` command-line switch.
614
- The choice of :func: `N_ ` here is totally arbitrary; it could have just
615
- as easily been :func: `MarkThisStringForTranslation `.
611
+ The choice of :func: `! N_ ` here is totally arbitrary; it could have just
612
+ as easily been :func: `! MarkThisStringForTranslation `.
616
613
617
614
618
615
Acknowledgements
0 commit comments