Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save felipe-prenholato/bdf3aacfcd2924b90410 to your computer and use it in GitHub Desktop.

Select an option

Save felipe-prenholato/bdf3aacfcd2924b90410 to your computer and use it in GitHub Desktop.
Python locale use sample
$ LC_ALL='es_MX.UTF-8' python foo.py
{'Default locale': ('es_MX', 'UTF-8'), 'Default locale data': ''}
{'Current locale data': '', 'Current locale': (None, None)}
{'Default locale': ('es_MX', 'UTF-8'),
'New locale': ('pt_BR', 'UTF-8'),
'New locale data': 'BRL '}
{'Current locale data': 'MXN ', 'Current locale': ('es_MX', 'UTF-8')}
# You must have pt_BR locale generated on yourt system (man locale-gen)
import locale
from pprint import pprint
pprint({"Default locale": locale.getdefaultlocale(), "Default locale data": locale.localeconv()['int_curr_symbol']})
print("")
print({"Current locale": locale.getlocale(), "Current locale data": locale.localeconv()['int_curr_symbol']})
print("")
def set_locale():
locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
pprint({"New locale": locale.getlocale(),
"Default locale": locale.getdefaultlocale(),
"New locale data": locale.localeconv()['int_curr_symbol']})
print("")
locale.resetlocale()
set_locale()
print({"Current locale": locale.getlocale(), "Current locale data": locale.localeconv()['int_curr_symbol']})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment