It seems you're using Windows. The locale strings are different there. Take a more precise look at the doc:

locale.setlocale(locale.LC_ALL, 'de_DE') # use German locale; name might vary with platform

On Windows, I think it would be something like:

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

MSDN has a list of language strings and of country/region strings

Answer from Schnouki on Stack Overflow
🌐
Python
docs.python.org › 3 › library › locale.html
locale — Internationalization services
Locale category for the character type functions. Most importantly, this category defines the text encoding, i.e. how bytes are interpreted as Unicode codepoints. See PEP 538 and PEP 540 for how this variable might be automatically coerced to C.UTF-8 to avoid issues created by invalid settings in containers or incompatible settings passed over remote SSH connections. Python doesn’t internally use locale-dependent character transformation functions from ctype.h.
🌐
Phrase
phrase.com › home › resources › blog › a beginner’s guide to python’s locale module
A Beginner's Guide to Python's locale Module | Phrase
September 25, 2022 - Python’s locale module is part of the standard library for internationalization (i18n) and localization (l10n) in Python. The locale module allows developers to deal with certain cultural issues in their applications.
🌐
Real Python
realpython.com › ref › stdlib › locale
locale | Python Standard Library – Real Python
The Python locale module provides tools to handle the localization of programs, such as formatting numbers, dates, and currencies according to the conventions of different locales.
🌐
Tutorialspoint
tutorialspoint.com › home › python › python locale module
Python Locale Module
April 13, 2025 - The locale module in Python is used to set and manage cultural conventions for formatting data.
🌐
Python Module of the Week
pymotw.com › 3 › locale
locale — Cultural Localization API
December 9, 2018 - The locale module is part of Python’s internationalization and localization support library. It provides a standard way to handle operations that may depend on the language or location of a user. For example, it handles formatting numbers as currency, comparing strings for sorting, and working ...
🌐
Vstinner
vstinner.github.io › python3-locales-encodings.html
Python 3, locales and encodings — Victor Stinner blog 3
September 6, 2018 - While testing my changes on Windows, I noticed that Python starts with the LC_CTYPE locale equal to "C", whereas locale.setlocale(locale.LC_CTYPE, "") changes the LC_CTYPE locale to something like English_United States.1252 (English with the code page 1252).
🌐
W3Schools
w3schools.com › python › ref_module_locale.asp
Python locale Module
Python Examples Python Compiler ... Python Bootcamp Python Certificate Python Training ... The locale module provides access to POSIX locale databases and functionality....
Find elsewhere
🌐
Python
svn.python.org › projects › python › trunk › Lib › locale.py
locale.py
__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error", "setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm", "str", "atof", "atoi", "format", "format_string", "currency", "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY", "LC_NUMERIC", "LC_ALL", "CHAR_MAX"] try: from _locale import * except ImportError: # Locale emulation CHAR_MAX = 127 LC_ALL = 6 LC_COLLATE = 3 LC_CTYPE = 0 LC_MESSAGES = 5 LC_MONETARY = 4 LC_NUMERIC = 1 LC_TIME = 2 Error = ValueError def localeconv(): """ localeconv() -> dict.
🌐
GitHub
github.com › python › cpython › blob › main › Lib › locale.py
cpython/Lib/locale.py at main · python/cpython
### Locale name aliasing engine · · # Author: Marc-Andre Lemburg, mal@lemburg.com · # Various tweaks by Fredrik Lundh <fredrik@pythonware.com> · # store away the low-level version of setlocale (it's · # overridden below) _setlocale = setlocale · · def _replace_encoding(code, encoding): if '.' in code: langname = code[:code.index('.')] else: langname = code ·
Author   python
🌐
Python Module of the Week
pymotw.com › 2 › locale
locale – POSIX cultural localization API - Python Module of the Week
... The locale module is part of Python’s internationalization and localization support library. It provides a standard way to handle operations that may depend on the language or location of a user. For example, it handles formatting numbers as currency, comparing strings for sorting, and ...
🌐
Squash
squash.io › complete-guide-how-to-use-python-locale
How to Use Python with Multiple Languages (Locale Guide)
November 23, 2023 - Locale is an essential aspect of software development that deals with language, cultural conventions, and formatting preferences. In Python, the locale module provides functionalities to handle various locale-related tasks.
🌐
SourceForge
pyspanishdoc.sourceforge.net › lib › module-locale.html
6.22 locale -- Internationalization services
The locale module opens access to the POSIX locale database and functionality.
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › locale.html
locale — Python Standard Library
The aliasing engine includes support for many commonly used locale names and maps them to values suitable for passing to the C lib’s setlocale() function.
🌐
O'Reilly
oreilly.com › library › view › python-standard-library › 0596000960 › ch08.html
8. Internationalization - Python Standard Library [Book]
May 10, 2001 - The locale module, as shown in Example 8-1, provides an interface to C’s localization functions. It also provides functions to convert between numbers and strings based on the current locale.
Author   Fredrik Lundh
Published   2001
Pages   304
Top answer
1 of 2
6

Unix systems don't really have a “system language”. Unix is a multiuser system and each user is free to pick their preferred language. The closest thing to a system language is the default language that users get if they don't configure their account. The location of that setting varies from distribution to distribution; it's picked up at some point during the login process.

In most cases, what is relevant is not the “system language” anyway, but the language that the user wants the application to use. Language preferences are expressed through locale settings. The setting that determines the language that applications should use in their user interface is LC_MESSAGES. There are also settings for the date, currency, etc. These settings are conveyed through environment variables which are usually set when the user logs in from some system- and user-dependent file.

Finding a locale setting is a bit more complicated than reading the LC_MESSAGES variable as several variables come into play (see What should I set my locale to and what are the implications of doing so?). There's a standard library function for that. In Python, use locale.getlocale. You first need to call setlocale to turn on locale awareness.

import locale
locale.setlocale(locale.LC_ALL, "")
message_language = locale.getlocale(locale.LC_MESSAGES)[0]
2 of 2
0

Since locale.getdefaultlocale() is deprecated, here is how I do it:

# This is needed, otherwise there is no locale info available
locale.setlocale(locale.LC_ALL, "")
locale_info = locale.getlocale()
# locale_info[0] contains a string similar to Dutch_Belgium
user_lang = locale_info[0].split('_')[0] if locale_info and locale_info[0] else 'English'
lang_code = locale.normalize(user_lang)[:2].lower() if locale.normalize(user_lang) else "en"

The code returns the language in the two-letter iso-639-1 format (for example en, nl, fr).

In this code example, the fallback value is "en" for English.

🌐
Python
peps.python.org › pep-0538
PEP 538 – Coercing the legacy C locale to a UTF-8 based locale | peps.python.org
LC_CTYPE=C.UTF-8 PYTHONIOENCODING=utf-8:surrogateescape · The exact target locale for coercion will be chosen from a predefined list at runtime based on the actually available locales.