all Python 3localefunction
locale.normalize()
locale setup
Turns a locale name into the form setlocale() understands, filling in region and encoding from a built-in alias table.
Syntax
locale.normalize(localename)
It is a pure lookup in Python's table, not a question to the system: the result does not guarantee the locale is installed, and setlocale() may still raise locale.Error. The encoding comes from the table, not UTF-8: 'en_US' becomes 'en_US.ISO8859-1'. An unknown name is returned unchanged, with no error.
Examples
import locale
print(locale.normalize('ru_RU.utf8')) # → ru_RU.UTF-8
print(locale.normalize('en_US')) # → en_US.ISO8859-1 — не UTF-8!
print(locale.normalize('xx')) # → xx — без ошибки
See also
Open in the full glossarydocs.python.orgReport an inaccuracy