Skip to main content

This package exposes part of the xlocale-family of C functions to Python. This is particularly useful to set the locale per-thread.

Normally you use the locale.setlocale function to change the locale for the entire process:

import locale

locale.setlocale(locale.LC_ALL, 'nl_NL')

This may not be desirable for webservers or other applications that use multiple threads. To change the locale for just the current thread you do this:

import xlocale

loc = xlocale.Locale(xlocale.LC_ALL_MASK, 'nl_NL')
loc.use()

Creating a locale object

xlocale.Locale([mask[, locale[, base]])

Create a new locale object. The new locale is created by taken a base locale and changing one or more locale categories. If no base is given the C locale will be used.

mask is a bitmask build from the LC_*_MASK constants. Normally you will want to use LC_ALL_MASK to change the locale completely.

locale is a string with the locale name. If not provided the C locale will be used.

xlocale.Locale.current_locale()

Return a Locale instance for the currently locale.

Locale instances

Locale.use()

Switch the locale for the current thread.

Locale.name(mask)

Return the name for a locale category. mask is a bitmask of locale categories, and the name for the first configured category will be returned.

This method is not available on all platforms, and will raise an exception on unsupported platforms.

Locale.lconv()

Return information describing how numbers and currency values must be displayed in the current locale. This is an object with the following attributes:

decimal_point

The decimal point character, except for currency values, cannot be an empty string.

thousands_sep

The separator between groups of digits before the decimal point, except for currency values.

grouping

The sizes of the groups of digits, except for currency This is a list of integers representing group size from low order digit groups to high order (right to left). The list may be terminated with 0 or CHAR_MAX. If the list is terminated with 0 the last group size before the 0 is repeated to account for all the digits. If the list isterminated with CHAR_MAX, no more grouping is performed.

int_curr_symbol

The standardized international currency symbol.

currency_symbol

The local currency symbol.

mon_decimal_point

The decimal point character for currency values.

mon_thousands_sep

The separator for digit groups in currency values.

mon_grouping

Like grouping but for currency values.

positive_sign

The character used to denote nonnegative currency values, usually the empty string.

negative_sign

The character used to denote negative currency values, usually a minus sign.

int_frac_digits

The number of digits after the decimal point in an international-style currency value.

frac_digits

The number of digits after the decimal point in the locale style for currency values.

p_cs_precedes

True if the currency symbol precedes the currency value for nonnegative values, False if it follows.

p_sep_by_space

True if a space is inserted between the currency symbol and the currency value for nonnegative values, False otherwise.

n_cs_precedes

Like p_cs_precedes but for negative values.

n_sep_by_space

Like p_sep_by_space but for negative values.

p_sign_posn

The location of the positive_sign with respect to a nonnegative quantity and the currency_symbol, coded as follows:

  • 0 - Parentheses around the entire string.

  • 1 - Before the string.

  • 2 - After the string.

  • 3 - Just before currency_symbol.

  • 4 - Just after currency_symbol.

n_sign_posn

Like p_sign_posn but for negative currency values.

int_p_cs_precedes

Same as p_cs_precedes, but for internationally monetary quantities. formatted monetary quantities.

int_n_cs_precedes

Same as n_cs_precedes, but for internationally monetary quantities. formatted monetary quantities.

int_p_sep_by_space

Same as p_sep_by_space, but for internationally formatted monetary quantities.

int_n_sep_by_space

Same as n_sep_by_space, but for internationally formatted monetary quantities.

int_p_sign_posn

Same as p_sign_posn, but for internationally formatted monetary quantities.

int_n_sign_posn

Same as n_sign_posn, but for internationally formatted monetary quantities.

Constants

Constant

Description

LC_COLLATE_MASK

Collation

LC_CTYPE_MASK

Character type

LC_MESSAGES_MASK

Messages

LC_MONETARY_MASK

Monetary

LC_NUMERIC_MASK

Numeric

LC_TIME_MASK

Time

LC_ALL_MASK

Combination of all of the above.

Changelog

1.3.4 - February 25, 2018

  • More Python 3 compilation fixes.

1.3.3 - February 25, 2018

  • Python 3 has no PyInt.

1.3.2 - February 25, 2018

  • Fix handling of exceptions raised when creating a Locale: they are now correctly seen as being raised in the constructor.

1.3.1 - February 23, 2018

  • Add Python 3 support.

  • Add manylinux support.

1.2 - November 15, 2014

  • No longer return the current locale from Locale.use(). This created unsolvable double free problems.

1.1 - October 10, 2014

  • Fix a memory handling error in Locale.use() which could result in a segfault when using a locale instance multiple times.

1.0 - August 27, 2014

  • First release

Metadata

Release files for xlocale 1.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xlocale 1.3.4
File Size Uploaded
xlocale-1.3.4.tar.gz 8.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for xlocale 1.3.4
File
xlocale-1.3.4-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
xlocale-1.3.4-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
xlocale-1.3.4-cp34-cp34m-manylinux1_x86_64.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64 Details
xlocale-1.3.4-cp33-cp33m-manylinux1_x86_64.whl CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64 Details
xlocale-1.3.4-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
xlocale-1.3.4-cp27-cp27m-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 Details

Total release size: 162.5 kB

Release files / xlocale-1.3.4.tar.gz

Download URL xlocale-1.3.4.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7d2949b2e248aca17f0f695fb2dd5cb439208510a1d6ef16f56ff88da8c1f0dd
BLAKE2b-256 checksum
How to use checksums
1633254885fa5b72964cde8508bfb0d770d99567a7209e28bcd75f2b6fd4d7c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp36-cp36m-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp36-cp36m-manylinux1_x86_64.whl
Size 25.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
d673f9f914ff70053d367484532459ab17a653904a89b32088c401de936674a9
BLAKE2b-256 checksum
How to use checksums
f6e879a1674b9072de88446d5ba610d6e75ee93e172843362fa03ba5b5d23a63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp35-cp35m-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp35-cp35m-manylinux1_x86_64.whl
Size 25.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
7a4715aaeec01027562f070c8b5760ec3b01a9bfa8582542f3e918e7d2d7d524
BLAKE2b-256 checksum
How to use checksums
145f13ec96fcabd4a69b423b54c732c5edc55f3fc0ff294c387241987b449e83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp34-cp34m-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp34-cp34m-manylinux1_x86_64.whl
Size 25.7 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
cefcb4db10b11e7b957a0ccb680d667b7171ffea6f6e1d977ff87cb3a6c7df0e
BLAKE2b-256 checksum
How to use checksums
813ddc5012442f8b8192e750295e10064e48cab486f58328a43829c9395d25e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp33-cp33m-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp33-cp33m-manylinux1_x86_64.whl
Size 25.6 kB
Tags CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c8e88466a5cddebc71dc9506691c5228a66750119fcac5346a08f1f60c9d95c9
BLAKE2b-256 checksum
How to use checksums
261db18003f6f342f7f7d1874daf11a00cd9fe208c77b31079673099aac67104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp27-cp27mu-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp27-cp27mu-manylinux1_x86_64.whl
Size 25.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
aa7dd462349ae8b23a5b7f0f5b15024cc4dc8668af27a10ed23b980408eb9260
BLAKE2b-256 checksum
How to use checksums
bfbd59eb4fd4cbcbc131d277822aeebc0009e9518ef9fe45984133f2231685f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xlocale-1.3.4-cp27-cp27m-manylinux1_x86_64.whl

Download URL xlocale-1.3.4-cp27-cp27m-manylinux1_x86_64.whl
Size 25.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
e81414534996daaae5af0f5d0d45abd6f2754d4f59daee20dafb86ff62e7f692
BLAKE2b-256 checksum
How to use checksums
4da5c65e3b1e48e5d145614fab7f44a28bb18efd24ed12a7257e7a119937a0d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.3.4 This release

7 release files

1.3.3

7 release files

1.3.2

7 release files

1.3.1

7 release files

1.2

1 release file

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page