Is there any way, in Python 3, to find out the language used by the system?
Even a tricky one though, like: reading from a file in a sneaky directory, and finding the string
'FRE' within the file's content…
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)