How can I (on a GNU/Linux system) find all available locales to use with the module locale
?
The only thing I find that is close in the the module is the dictionary locale_alias
with aliases for locales.
That is sometimes mentioned as where to look what locales you have, but it doesn't contain all aliases. On my system this program
#! /usr/bin/python3
import locale
for k, v in sorted(locale.locale_alias.items()):
if k.startswith('fr_') or v.startswith('fr_'):
print('{:20}{}'.format(k, v))
prints
c-french fr_CA.ISO8859-1
fr fr_FR.ISO8859-1
fr_be fr_BE.ISO8859-1
fr_ca fr_CA.ISO8859-1
fr_ch fr_CH.ISO8859-1
fr_fr fr_FR.ISO8859-1
fr_lu fr_LU.ISO8859-1
français fr_FR.ISO8859-1
fre_fr fr_FR.ISO8859-1
french fr_FR.ISO8859-1
french.iso88591 fr_CH.ISO8859-1
french_france fr_FR.ISO8859-1
ignoring all utf-8 locales, like 'fr_FR.utf8'
, which can indeed be used as argument for locale.setlocale
. From the shell, locale -a | grep "^fr_.*utf8"
gives
fr_BE.utf8
fr_CA.utf8
fr_CH.utf8
fr_FR.utf8
fr_LU.utf8
showing lots of options. (One way is of course to run this shell command from Python, but I would have thought there is a way to do this directly from Python.)