Chapter XV: internationalization and localization -gettext: Message catalog - Find runtime message catalog

15.1.3 runtime lookup message catalogs
described above, comprising the message catalog locale directory organized according to language, encoded by domain naming program. Different operating systems define their default values, but gettext does not know all these defaults. It uses a default locale directory sys.prefix + '/ share / locale' , but in most cases, a safer approach is to explicitly provide a localeddir value and not expect the default value is always legitimate. find () function is responsible for finding a suitable message catalog at run time.

import gettext

catalogs = gettext.find('example','locale',all=True)
print('Catalogs:',catalogs)

Obtained by the language part of the path of an environment variable (LAGUAGE, LC_ALL, LC_MESSAGE and LANG), these environmental variables can be used to configure the localization features. Always uses the first variable found. To select multiple languages, you may be (:) value separated by a colon.

Guess you like

Origin blog.csdn.net/weixin_43193719/article/details/94757600