问题
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!
回答1:
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.
回答2:
Have a look at getenv and setenv in relation to the environment variables LANGUAGE etc.
This has to do with locales.
http://billposer.org/Software/NumbersAndLocales.html
Be sure to note the different meanings of all the variables. There are overrides through LC_ALL etc.
回答3:
To determine a current language on a system you can look at the following environment variables (sorted by priority in descending order):
LANGUAGE
LC_ALL
LC_MESSAGES
,LC_NUMERIC
,LC_TIME
,LC_COLLATE
, and othersLANG
Each 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
来源:https://stackoverflow.com/questions/3338279/find-out-default-language-on-linux