Find out default language on Linux

允我心安 提交于 2019-12-25 03:19:09

问题


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):

  1. LANGUAGE
  2. LC_ALL
  3. LC_MESSAGES, LC_NUMERIC, LC_TIME, LC_COLLATE, and others
  4. LANG

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!