blob: bc7f5f932be87cf44296ed3bcca5b15634755c59 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`locale` --- Internationalization services
2===============================================
3
4.. module:: locale
5 :synopsis: Internationalization services.
6.. moduleauthor:: Martin von Löwis <martin@v.loewis.de>
7.. sectionauthor:: Martin von Löwis <martin@v.loewis.de>
8
9
10The :mod:`locale` module opens access to the POSIX locale database and
11functionality. The POSIX locale mechanism allows programmers to deal with
12certain cultural issues in an application, without requiring the programmer to
13know all the specifics of each country where the software is executed.
14
15.. index:: module: _locale
16
17The :mod:`locale` module is implemented on top of the :mod:`_locale` module,
18which in turn uses an ANSI C locale implementation if available.
19
20The :mod:`locale` module defines the following exception and functions:
21
22
23.. exception:: Error
24
Petri Lehtinen395ca722011-11-05 10:18:50 +020025 Exception raised when the locale passed to :func:`setlocale` is not
26 recognized.
Georg Brandl116aa622007-08-15 14:28:22 +000027
28
Georg Brandlcd7f32b2009-06-08 09:13:45 +000029.. function:: setlocale(category, locale=None)
Georg Brandl116aa622007-08-15 14:28:22 +000030
Petri Lehtinen395ca722011-11-05 10:18:50 +020031 If *locale* is given and not ``None``, :func:`setlocale` modifies the locale
32 setting for the *category*. The available categories are listed in the data
33 description below. *locale* may be a string, or an iterable of two strings
34 (language code and encoding). If it's an iterable, it's converted to a locale
35 name using the locale aliasing engine. An empty string specifies the user's
36 default settings. If the modification of the locale fails, the exception
37 :exc:`Error` is raised. If successful, the new locale setting is returned.
Georg Brandl116aa622007-08-15 14:28:22 +000038
39 If *locale* is omitted or ``None``, the current setting for *category* is
40 returned.
41
Georg Brandlf285bcc2010-10-19 21:07:16 +000042 :func:`setlocale` is not thread-safe on most systems. Applications typically
Georg Brandl116aa622007-08-15 14:28:22 +000043 start with a call of ::
44
45 import locale
46 locale.setlocale(locale.LC_ALL, '')
47
48 This sets the locale for all categories to the user's default setting (typically
49 specified in the :envvar:`LANG` environment variable). If the locale is not
50 changed thereafter, using multithreading should not cause problems.
51
Georg Brandl116aa622007-08-15 14:28:22 +000052
53.. function:: localeconv()
54
55 Returns the database of the local conventions as a dictionary. This dictionary
56 has the following strings as keys:
57
Georg Brandl44ea77b2013-03-28 13:28:44 +010058 .. tabularcolumns:: |l|l|L|
59
Georg Brandl116aa622007-08-15 14:28:22 +000060 +----------------------+-------------------------------------+--------------------------------+
61 | Category | Key | Meaning |
62 +======================+=====================================+================================+
63 | :const:`LC_NUMERIC` | ``'decimal_point'`` | Decimal point character. |
64 +----------------------+-------------------------------------+--------------------------------+
65 | | ``'grouping'`` | Sequence of numbers specifying |
66 | | | which relative positions the |
67 | | | ``'thousands_sep'`` is |
68 | | | expected. If the sequence is |
69 | | | terminated with |
70 | | | :const:`CHAR_MAX`, no further |
71 | | | grouping is performed. If the |
72 | | | sequence terminates with a |
73 | | | ``0``, the last group size is |
74 | | | repeatedly used. |
75 +----------------------+-------------------------------------+--------------------------------+
76 | | ``'thousands_sep'`` | Character used between groups. |
77 +----------------------+-------------------------------------+--------------------------------+
78 | :const:`LC_MONETARY` | ``'int_curr_symbol'`` | International currency symbol. |
79 +----------------------+-------------------------------------+--------------------------------+
80 | | ``'currency_symbol'`` | Local currency symbol. |
81 +----------------------+-------------------------------------+--------------------------------+
82 | | ``'p_cs_precedes/n_cs_precedes'`` | Whether the currency symbol |
83 | | | precedes the value (for |
84 | | | positive resp. negative |
85 | | | values). |
86 +----------------------+-------------------------------------+--------------------------------+
87 | | ``'p_sep_by_space/n_sep_by_space'`` | Whether the currency symbol is |
88 | | | separated from the value by a |
89 | | | space (for positive resp. |
90 | | | negative values). |
91 +----------------------+-------------------------------------+--------------------------------+
92 | | ``'mon_decimal_point'`` | Decimal point used for |
93 | | | monetary values. |
94 +----------------------+-------------------------------------+--------------------------------+
95 | | ``'frac_digits'`` | Number of fractional digits |
96 | | | used in local formatting of |
97 | | | monetary values. |
98 +----------------------+-------------------------------------+--------------------------------+
99 | | ``'int_frac_digits'`` | Number of fractional digits |
100 | | | used in international |
101 | | | formatting of monetary values. |
102 +----------------------+-------------------------------------+--------------------------------+
103 | | ``'mon_thousands_sep'`` | Group separator used for |
104 | | | monetary values. |
105 +----------------------+-------------------------------------+--------------------------------+
106 | | ``'mon_grouping'`` | Equivalent to ``'grouping'``, |
107 | | | used for monetary values. |
108 +----------------------+-------------------------------------+--------------------------------+
109 | | ``'positive_sign'`` | Symbol used to annotate a |
110 | | | positive monetary value. |
111 +----------------------+-------------------------------------+--------------------------------+
112 | | ``'negative_sign'`` | Symbol used to annotate a |
113 | | | negative monetary value. |
114 +----------------------+-------------------------------------+--------------------------------+
115 | | ``'p_sign_posn/n_sign_posn'`` | The position of the sign (for |
116 | | | positive resp. negative |
117 | | | values), see below. |
118 +----------------------+-------------------------------------+--------------------------------+
119
120 All numeric values can be set to :const:`CHAR_MAX` to indicate that there is no
121 value specified in this locale.
122
123 The possible values for ``'p_sign_posn'`` and ``'n_sign_posn'`` are given below.
124
125 +--------------+-----------------------------------------+
126 | Value | Explanation |
127 +==============+=========================================+
128 | ``0`` | Currency and value are surrounded by |
129 | | parentheses. |
130 +--------------+-----------------------------------------+
131 | ``1`` | The sign should precede the value and |
132 | | currency symbol. |
133 +--------------+-----------------------------------------+
134 | ``2`` | The sign should follow the value and |
135 | | currency symbol. |
136 +--------------+-----------------------------------------+
137 | ``3`` | The sign should immediately precede the |
138 | | value. |
139 +--------------+-----------------------------------------+
140 | ``4`` | The sign should immediately follow the |
141 | | value. |
142 +--------------+-----------------------------------------+
143 | ``CHAR_MAX`` | Nothing is specified in this locale. |
144 +--------------+-----------------------------------------+
145
146
147.. function:: nl_langinfo(option)
148
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000149 Return some locale-specific information as a string. This function is not
150 available on all systems, and the set of possible options might also vary
151 across platforms. The possible argument values are numbers, for which
152 symbolic constants are available in the locale module.
153
154 The :func:`nl_langinfo` function accepts one of the following keys. Most
155 descriptions are taken from the corresponding description in the GNU C
156 library.
157
158 .. data:: CODESET
159
160 Get a string with the name of the character encoding used in the
161 selected locale.
162
163 .. data:: D_T_FMT
164
Sandro Tosi964f2052012-06-02 18:22:02 +0200165 Get a string that can be used as a format string for :func:`time.strftime` to
Georg Brandl1d0a0f52011-03-06 11:09:51 +0100166 represent date and time in a locale-specific way.
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000167
168 .. data:: D_FMT
169
Sandro Tosi964f2052012-06-02 18:22:02 +0200170 Get a string that can be used as a format string for :func:`time.strftime` to
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000171 represent a date in a locale-specific way.
172
173 .. data:: T_FMT
174
Sandro Tosi964f2052012-06-02 18:22:02 +0200175 Get a string that can be used as a format string for :func:`time.strftime` to
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000176 represent a time in a locale-specific way.
177
178 .. data:: T_FMT_AMPM
179
Sandro Tosi964f2052012-06-02 18:22:02 +0200180 Get a format string for :func:`time.strftime` to represent time in the am/pm
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000181 format.
182
183 .. data:: DAY_1 ... DAY_7
184
185 Get the name of the n-th day of the week.
186
187 .. note::
188
189 This follows the US convention of :const:`DAY_1` being Sunday, not the
190 international convention (ISO 8601) that Monday is the first day of the
191 week.
192
193 .. data:: ABDAY_1 ... ABDAY_7
194
195 Get the abbreviated name of the n-th day of the week.
196
197 .. data:: MON_1 ... MON_12
198
199 Get the name of the n-th month.
200
201 .. data:: ABMON_1 ... ABMON_12
202
203 Get the abbreviated name of the n-th month.
204
205 .. data:: RADIXCHAR
206
207 Get the radix character (decimal dot, decimal comma, etc.)
208
209 .. data:: THOUSEP
210
211 Get the separator character for thousands (groups of three digits).
212
213 .. data:: YESEXPR
214
215 Get a regular expression that can be used with the regex function to
216 recognize a positive response to a yes/no question.
217
218 .. note::
219
Georg Brandl60203b42010-10-06 10:11:56 +0000220 The expression is in the syntax suitable for the :c:func:`regex` function
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000221 from the C library, which might differ from the syntax used in :mod:`re`.
222
223 .. data:: NOEXPR
224
225 Get a regular expression that can be used with the regex(3) function to
226 recognize a negative response to a yes/no question.
227
228 .. data:: CRNCYSTR
229
230 Get the currency symbol, preceded by "-" if the symbol should appear before
231 the value, "+" if the symbol should appear after the value, or "." if the
232 symbol should replace the radix character.
233
234 .. data:: ERA
235
236 Get a string that represents the era used in the current locale.
237
238 Most locales do not define this value. An example of a locale which does
239 define this value is the Japanese one. In Japan, the traditional
240 representation of dates includes the name of the era corresponding to the
241 then-emperor's reign.
242
243 Normally it should not be necessary to use this value directly. Specifying
Sandro Tosi964f2052012-06-02 18:22:02 +0200244 the ``E`` modifier in their format strings causes the :func:`time.strftime`
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000245 function to use this information. The format of the returned string is not
246 specified, and therefore you should not assume knowledge of it on different
247 systems.
248
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000249 .. data:: ERA_D_T_FMT
250
Sandro Tosi964f2052012-06-02 18:22:02 +0200251 Get a format string for :func:`time.strftime` to represent date and time in a
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000252 locale-specific era-based way.
253
254 .. data:: ERA_D_FMT
255
Sandro Tosi964f2052012-06-02 18:22:02 +0200256 Get a format string for :func:`time.strftime` to represent a date in a
Georg Brandl1d0a0f52011-03-06 11:09:51 +0100257 locale-specific era-based way.
258
259 .. data:: ERA_T_FMT
260
Sandro Tosi964f2052012-06-02 18:22:02 +0200261 Get a format string for :func:`time.strftime` to represent a time in a
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000262 locale-specific era-based way.
263
264 .. data:: ALT_DIGITS
265
266 Get a representation of up to 100 values used to represent the values
267 0 to 99.
Georg Brandl116aa622007-08-15 14:28:22 +0000268
269
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000270.. function:: getdefaultlocale([envvars])
Georg Brandl116aa622007-08-15 14:28:22 +0000271
272 Tries to determine the default locale settings and returns them as a tuple of
273 the form ``(language code, encoding)``.
274
275 According to POSIX, a program which has not called ``setlocale(LC_ALL, '')``
276 runs using the portable ``'C'`` locale. Calling ``setlocale(LC_ALL, '')`` lets
277 it use the default locale as defined by the :envvar:`LANG` variable. Since we
278 do not want to interfere with the current locale setting we thus emulate the
279 behavior in the way described above.
280
281 To maintain compatibility with other platforms, not only the :envvar:`LANG`
282 variable is tested, but a list of variables given as envvars parameter. The
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000283 first found to be defined will be used. *envvars* defaults to the search
284 path used in GNU gettext; it must always contain the variable name
285 ``'LANG'``. The GNU gettext search path contains ``'LC_ALL'``,
286 ``'LC_CTYPE'``, ``'LANG'`` and ``'LANGUAGE'``, in that order.
Georg Brandl116aa622007-08-15 14:28:22 +0000287
288 Except for the code ``'C'``, the language code corresponds to :rfc:`1766`.
289 *language code* and *encoding* may be ``None`` if their values cannot be
290 determined.
291
Georg Brandl116aa622007-08-15 14:28:22 +0000292
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000293.. function:: getlocale(category=LC_CTYPE)
Georg Brandl116aa622007-08-15 14:28:22 +0000294
295 Returns the current setting for the given locale category as sequence containing
296 *language code*, *encoding*. *category* may be one of the :const:`LC_\*` values
297 except :const:`LC_ALL`. It defaults to :const:`LC_CTYPE`.
298
299 Except for the code ``'C'``, the language code corresponds to :rfc:`1766`.
300 *language code* and *encoding* may be ``None`` if their values cannot be
301 determined.
302
Georg Brandl116aa622007-08-15 14:28:22 +0000303
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000304.. function:: getpreferredencoding(do_setlocale=True)
Georg Brandl116aa622007-08-15 14:28:22 +0000305
306 Return the encoding used for text data, according to user preferences. User
307 preferences are expressed differently on different systems, and might not be
308 available programmatically on some systems, so this function only returns a
309 guess.
310
311 On some systems, it is necessary to invoke :func:`setlocale` to obtain the user
312 preferences, so this function is not thread-safe. If invoking setlocale is not
313 necessary or desired, *do_setlocale* should be set to ``False``.
314
Georg Brandl116aa622007-08-15 14:28:22 +0000315
316.. function:: normalize(localename)
317
318 Returns a normalized locale code for the given locale name. The returned locale
319 code is formatted for use with :func:`setlocale`. If normalization fails, the
320 original name is returned unchanged.
321
322 If the given encoding is not known, the function defaults to the default
323 encoding for the locale code just like :func:`setlocale`.
324
Georg Brandl116aa622007-08-15 14:28:22 +0000325
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000326.. function:: resetlocale(category=LC_ALL)
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328 Sets the locale for *category* to the default setting.
329
330 The default setting is determined by calling :func:`getdefaultlocale`.
331 *category* defaults to :const:`LC_ALL`.
332
Georg Brandl116aa622007-08-15 14:28:22 +0000333
334.. function:: strcoll(string1, string2)
335
336 Compares two strings according to the current :const:`LC_COLLATE` setting. As
337 any other compare function, returns a negative, or a positive value, or ``0``,
338 depending on whether *string1* collates before or after *string2* or is equal to
339 it.
340
341
342.. function:: strxfrm(string)
343
Mark Dickinsonc48d8342009-02-01 14:18:10 +0000344 Transforms a string to one that can be used in locale-aware
345 comparisons. For example, ``strxfrm(s1) < strxfrm(s2)`` is
346 equivalent to ``strcoll(s1, s2) < 0``. This function can be used
347 when the same string is compared repeatedly, e.g. when collating a
348 sequence of strings.
Georg Brandl116aa622007-08-15 14:28:22 +0000349
350
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000351.. function:: format(format, val, grouping=False, monetary=False)
Georg Brandl116aa622007-08-15 14:28:22 +0000352
353 Formats a number *val* according to the current :const:`LC_NUMERIC` setting.
354 The format follows the conventions of the ``%`` operator. For floating point
355 values, the decimal point is modified if appropriate. If *grouping* is true,
356 also takes the grouping into account.
357
358 If *monetary* is true, the conversion uses monetary thousands separator and
359 grouping strings.
360
361 Please note that this function will only work for exactly one %char specifier.
362 For whole format strings, use :func:`format_string`.
363
Georg Brandl116aa622007-08-15 14:28:22 +0000364
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000365.. function:: format_string(format, val, grouping=False)
Georg Brandl116aa622007-08-15 14:28:22 +0000366
367 Processes formatting specifiers as in ``format % val``, but takes the current
368 locale settings into account.
369
Georg Brandl116aa622007-08-15 14:28:22 +0000370
Georg Brandlcd7f32b2009-06-08 09:13:45 +0000371.. function:: currency(val, symbol=True, grouping=False, international=False)
Georg Brandl116aa622007-08-15 14:28:22 +0000372
373 Formats a number *val* according to the current :const:`LC_MONETARY` settings.
374
375 The returned string includes the currency symbol if *symbol* is true, which is
376 the default. If *grouping* is true (which is not the default), grouping is done
377 with the value. If *international* is true (which is not the default), the
378 international currency symbol is used.
379
380 Note that this function will not work with the 'C' locale, so you have to set a
381 locale via :func:`setlocale` first.
382
Georg Brandl116aa622007-08-15 14:28:22 +0000383
384.. function:: str(float)
385
386 Formats a floating point number using the same format as the built-in function
387 ``str(float)``, but takes the decimal point into account.
388
389
Antoine Pitroub64bca92014-10-23 22:52:31 +0200390.. function:: delocalize(string)
391
392 Converts a string into a normalized number string, following the
Antoine Pitrou821b5a12014-10-23 23:03:35 +0200393 :const:`LC_NUMERIC` settings.
Antoine Pitroub64bca92014-10-23 22:52:31 +0200394
395 .. versionadded:: 3.5
396
397
Georg Brandl116aa622007-08-15 14:28:22 +0000398.. function:: atof(string)
399
400 Converts a string to a floating point number, following the :const:`LC_NUMERIC`
401 settings.
402
403
404.. function:: atoi(string)
405
406 Converts a string to an integer, following the :const:`LC_NUMERIC` conventions.
407
408
409.. data:: LC_CTYPE
410
411 .. index:: module: string
412
413 Locale category for the character type functions. Depending on the settings of
414 this category, the functions of module :mod:`string` dealing with case change
415 their behaviour.
416
417
418.. data:: LC_COLLATE
419
420 Locale category for sorting strings. The functions :func:`strcoll` and
421 :func:`strxfrm` of the :mod:`locale` module are affected.
422
423
424.. data:: LC_TIME
425
426 Locale category for the formatting of time. The function :func:`time.strftime`
427 follows these conventions.
428
429
430.. data:: LC_MONETARY
431
432 Locale category for formatting of monetary values. The available options are
433 available from the :func:`localeconv` function.
434
435
436.. data:: LC_MESSAGES
437
438 Locale category for message display. Python currently does not support
439 application specific locale-aware messages. Messages displayed by the operating
440 system, like those returned by :func:`os.strerror` might be affected by this
441 category.
442
443
444.. data:: LC_NUMERIC
445
Georg Brandl502d9a52009-07-26 15:02:41 +0000446 Locale category for formatting numbers. The functions :func:`.format`,
447 :func:`atoi`, :func:`atof` and :func:`.str` of the :mod:`locale` module are
Georg Brandl116aa622007-08-15 14:28:22 +0000448 affected by that category. All other numeric formatting operations are not
449 affected.
450
451
452.. data:: LC_ALL
453
454 Combination of all locale settings. If this flag is used when the locale is
455 changed, setting the locale for all categories is attempted. If that fails for
456 any category, no category is changed at all. When the locale is retrieved using
457 this flag, a string indicating the setting for all categories is returned. This
458 string can be later used to restore the settings.
459
460
461.. data:: CHAR_MAX
462
463 This is a symbolic constant used for different values returned by
464 :func:`localeconv`.
465
Georg Brandl116aa622007-08-15 14:28:22 +0000466
467Example::
468
469 >>> import locale
Benjamin Petersonf608c612008-11-16 18:33:53 +0000470 >>> loc = locale.getlocale() # get current locale
Alexandre Vassalotti711ed4a2009-07-17 10:42:05 +0000471 # use German locale; name might vary with platform
472 >>> locale.setlocale(locale.LC_ALL, 'de_DE')
Georg Brandl48310cd2009-01-03 21:18:54 +0000473 >>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut
Georg Brandl116aa622007-08-15 14:28:22 +0000474 >>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale
475 >>> locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale
476 >>> locale.setlocale(locale.LC_ALL, loc) # restore saved locale
477
478
479Background, details, hints, tips and caveats
480--------------------------------------------
481
482The C standard defines the locale as a program-wide property that may be
483relatively expensive to change. On top of that, some implementation are broken
484in such a way that frequent locale changes may cause core dumps. This makes the
485locale somewhat painful to use correctly.
486
487Initially, when a program is started, the locale is the ``C`` locale, no matter
Victor Stinnera01f1ad2012-06-06 01:37:37 +0200488what the user's preferred locale is. There is one exception: the
489:data:`LC_CTYPE` category is changed at startup to set the current locale
490encoding to the user's preferred locale encoding. The program must explicitly
491say that it wants the user's preferred locale settings for other categories by
492calling ``setlocale(LC_ALL, '')``.
Georg Brandl116aa622007-08-15 14:28:22 +0000493
494It is generally a bad idea to call :func:`setlocale` in some library routine,
495since as a side effect it affects the entire program. Saving and restoring it
496is almost as bad: it is expensive and affects other threads that happen to run
497before the settings have been restored.
498
499If, when coding a module for general use, you need a locale independent version
Guido van Rossum8d2ef872007-10-15 15:42:31 +0000500of an operation that is affected by the locale (such as
Georg Brandl116aa622007-08-15 14:28:22 +0000501certain formats used with :func:`time.strftime`), you will have to find a way to
502do it without using the standard library routine. Even better is convincing
503yourself that using locale settings is okay. Only as a last resort should you
504document that your module is not compatible with non-\ ``C`` locale settings.
505
Georg Brandl116aa622007-08-15 14:28:22 +0000506The only way to perform numeric operations according to the locale is to use the
507special functions defined by this module: :func:`atof`, :func:`atoi`,
Georg Brandl502d9a52009-07-26 15:02:41 +0000508:func:`.format`, :func:`.str`.
Georg Brandl116aa622007-08-15 14:28:22 +0000509
Guido van Rossum8d2ef872007-10-15 15:42:31 +0000510There is no way to perform case conversions and character classifications
511according to the locale. For (Unicode) text strings these are done according
512to the character value only, while for byte strings, the conversions and
513classifications are done according to the ASCII value of the byte, and bytes
514whose high bit is set (i.e., non-ASCII bytes) are never converted or considered
515part of a character class such as letter or whitespace.
516
Georg Brandl116aa622007-08-15 14:28:22 +0000517
518.. _embedding-locale:
519
520For extension writers and programs that embed Python
521----------------------------------------------------
522
523Extension modules should never call :func:`setlocale`, except to find out what
524the current locale is. But since the return value can only be used portably to
525restore it, that is not very useful (except perhaps to find out whether or not
526the locale is ``C``).
527
528When Python code uses the :mod:`locale` module to change the locale, this also
529affects the embedding application. If the embedding application doesn't want
530this to happen, it should remove the :mod:`_locale` extension module (which does
531all the work) from the table of built-in modules in the :file:`config.c` file,
532and make sure that the :mod:`_locale` module is not accessible as a shared
533library.
534
535
536.. _locale-gettext:
537
538Access to message catalogs
539--------------------------
540
541The locale module exposes the C library's gettext interface on systems that
542provide this interface. It consists of the functions :func:`gettext`,
543:func:`dgettext`, :func:`dcgettext`, :func:`textdomain`, :func:`bindtextdomain`,
544and :func:`bind_textdomain_codeset`. These are similar to the same functions in
545the :mod:`gettext` module, but use the C library's binary format for message
546catalogs, and the C library's search algorithms for locating message catalogs.
547
548Python applications should normally find no need to invoke these functions, and
549should use :mod:`gettext` instead. A known exception to this rule are
Georg Brandl599dbfc2010-10-26 19:58:11 +0000550applications that link with additional C libraries which internally invoke
Georg Brandl60203b42010-10-06 10:11:56 +0000551:c:func:`gettext` or :func:`dcgettext`. For these applications, it may be
Georg Brandl116aa622007-08-15 14:28:22 +0000552necessary to bind the text domain, so that the libraries can properly locate
553their message catalogs.
554