Hướng dẫn install locale python
Source code: Lib/locale.py Show The The The
locale. Error ¶Exception raised when the locale passed to
locale. setlocale (category, locale=None)¶If locale is given and
not If locale is omitted or
import locale locale.setlocale(locale.LC_ALL, '') This sets the locale for all categories to the user’s default setting (typically specified in the locale. localeconv ()¶Returns the database of the local conventions as a dictionary. This dictionary has the following strings as keys:
All numeric values can be set to The possible values for
The function sets temporarily the Changed in version 3.7: The function now sets temporarily the locale. nl_langinfo (option)¶Return some locale-specific information as a string. This function is not available on all systems, and the set of possible options might also vary across platforms. The possible argument values are numbers, for which symbolic constants are available in the locale module. The locale. CODESET ¶Get a string with the name of the character encoding used in the selected locale. locale. D_T_FMT ¶Get a string that can be used as a format string for locale. D_FMT ¶Get a string that can be used as a format string for locale. T_FMT ¶Get a string that can be used as a format string for locale. T_FMT_AMPM ¶Get a format string for DAY_1 ... DAY_7 Get the name of the n-th day of the week. Note This follows the US
convention of ABDAY_1 ... ABDAY_7 Get the abbreviated name of the n-th day of the week. MON_1 ... MON_12 Get the name of the n-th month. ABMON_1 ... ABMON_12 Get the abbreviated name of the n-th month. locale. RADIXCHAR ¶Get the radix character (decimal dot, decimal comma, etc.). locale. THOUSEP ¶Get the separator character for thousands (groups of three digits). locale. YESEXPR ¶Get a regular expression that can be used with the regex function to recognize a positive response to a yes/no question. Note The expression is in the syntax suitable for the locale. NOEXPR ¶Get a regular expression that can be used with the regex(3) function to recognize a negative response to a yes/no question. locale. CRNCYSTR ¶Get the currency symbol, preceded by “-” if the symbol should appear before the value, “+” if the symbol should appear after the value, or “.” if the symbol should replace the radix character. locale. ERA ¶Get a string that represents the era used in the current locale. Most locales do not define this value. An example of a locale which does define this value is the Japanese one. In Japan, the traditional representation of dates includes the name of the era corresponding to the then-emperor’s reign. Normally it
should not be necessary to use this value directly. Specifying the locale. ERA_D_T_FMT ¶Get a format string for locale. ERA_D_FMT ¶Get a format string for locale. ERA_T_FMT ¶Get a format string for locale. ALT_DIGITS ¶Get a representation of up to 100 values used to represent the values 0 to 99. locale. getdefaultlocale ([envvars])¶Tries to determine the default locale settings and returns them as a tuple of the form According to POSIX, a program which has not called To maintain compatibility with other platforms, not only the Except for the code locale. getlocale (category=LC_CTYPE)¶Returns the current setting for the given locale category as sequence containing language code, encoding. category may be one of the Except for the code locale. getpreferredencoding (do_setlocale=True)¶Return the locale encoding used for text data, according to user preferences. User preferences are expressed differently on different systems, and might not be available programmatically on some systems, so this function only returns a guess. On some systems, it is necessary to invoke On Android or if the Python UTF-8 Mode is enabled, always return The Python preinitialization configures the LC_CTYPE locale. See also the filesystem encoding and error handler. Changed in version 3.7: The function now always returns locale. normalize (localename)¶Returns a normalized locale code for the given locale name. The returned locale code is formatted for use with
If the given encoding is not known, the function defaults to the default encoding for the locale code just like locale. resetlocale (category=LC_ALL)¶Sets the locale for category to the default setting. The default setting is determined by calling
locale. strcoll (string1,
string2)¶Compares two strings according to the current locale. strxfrm (string)¶Transforms a string to one that can be used in locale-aware comparisons. For example, locale. format_string (format, val, grouping=False, monetary=False)¶Formats a number val
according to the current If monetary is true, the conversion uses monetary thousands separator and grouping strings. Processes formatting
specifiers as in Changed in version 3.7: The monetary keyword parameter was added. locale. format (format, val, grouping=False,
monetary=False)¶Please note that this function works like For whole format strings, use locale. currency (val, symbol=True, grouping=False,
international=False)¶Formats a number val according to the current The returned string includes the currency symbol if symbol is true, which is the default. If grouping is true (which is not the default), grouping is done with the value. If international is true (which is not the default), the international currency symbol is used. Note that this function will not work with the ‘C’ locale, so you have to set a locale via locale. str (float)¶Formats a floating point number using the same format as the built-in function locale. delocalize (string)¶Converts a string into a normalized number string, following the New in version 3.5. locale. localize (string, grouping=False, monetary=False)¶Converts a normalized number string into a formatted string following the
New in version 3.10. locale. atof (string, func=float)¶Converts a
string to a number, following the locale. atoi (string)¶Converts a string to an integer, following the locale. LC_CTYPE ¶Locale category for the character type functions. Depending on the settings of this category, the functions of module locale. LC_COLLATE ¶Locale category for sorting strings. The functions locale. LC_TIME ¶Locale category for the formatting of time. The function locale. LC_MONETARY ¶Locale category for formatting of monetary values. The available options are available from the locale. LC_MESSAGES ¶Locale category for message display. Python currently does not support application specific locale-aware messages. Messages displayed by the operating system, like those returned by locale. LC_NUMERIC ¶Locale category for formatting numbers. The functions locale. LC_ALL ¶Combination of all locale settings. If this flag is used when the locale is changed, setting the locale for all categories is attempted. If that fails for any category, no category is changed at all. When the locale is retrieved using this flag, a string indicating the setting for all categories is returned. This string can be later used to restore the settings. locale. CHAR_MAX ¶This is a symbolic constant used for different values returned by Example: >>> import locale >>> loc = locale.getlocale() # get current locale # use German locale; name might vary with platform >>> locale.setlocale(locale.LC_ALL, 'de_DE') >>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut >>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale >>> locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale >>> locale.setlocale(locale.LC_ALL, loc) # restore saved locale Background, details, hints, tips and caveats¶The C standard defines the locale as a program-wide property that may be relatively expensive to change. On top of that, some implementations are broken in such a way that frequent locale changes may cause core dumps. This makes the locale somewhat painful to use correctly. Initially, when a program
is started, the locale is the It is generally
a bad idea to call If, when coding a module for general use, you need a locale independent version of an operation that is affected by the locale
(such as certain formats used with The only way to perform numeric operations according to the locale is to
use the special functions defined by this module: There is no way to perform case conversions and character classifications according to the locale. For (Unicode) text strings these are done according to the character value only, while for byte strings, the conversions and classifications are done according to the ASCII value of the byte, and bytes whose high bit is set (i.e., non-ASCII bytes) are never converted or considered part of a character class such as letter or whitespace. For extension writers and programs that embed Python¶Extension modules should never call
When Python code uses the
Access to message catalogs¶locale. gettext (msg)¶
locale. dgettext (domain, msg)¶ locale. dcgettext (domain, msg,
category)¶ locale. textdomain (domain)¶
locale. bindtextdomain (domain, dir)¶The locale module exposes the C library’s gettext interface on systems that provide this interface. It consists of the functions Python applications should normally find no need to invoke these functions, and should use
|