Is there a way to find out the default language of a Linux system from C? Is there a POSIX API for this? E.g. I'd like to have a string in human readable format, i.e. "German" or "Deutsch" on a German system, "French" or "Francais" on a French system etc. Is there something like this?
Thanks!
To determine a current language on a system you can look at the following environment variables (sorted by priority in descending order):
LANGUAGELC_ALLLC_MESSAGES, LC_NUMERIC, LC_TIME, LC_COLLATE, and othersLANGEach of these variables has a special format: ll_CC, where the first two letters mean language code, the second two ones mean country code. Also an additional information like charset or variant may be specified. As exception, the first variable can contain list of language codes, and it works only if localization mechanism is enabled.
At least, gettext, the most popular translation framework in Unix-like OS, is guided by these rules.
https://gnu.org/software/gettext/manual/html_node/gettext_2.html#Locale-Environment-Variables
Usually, the LANG environment variable contains that information in the format like "de_DE.UTF-8".
You can retrieve it using the getenv function.
EDIT:
For more sophisticated internationalization, you might want to look into gettext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With