找出Linux上的默认语言 [英] Find out default language on Linux

查看:135
本文介绍了找出Linux上的默认语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从C中找出Linux系统的默认语言?是否有POSIX API?例如.我想使用人类可读格式的字符串,即在德语系统中为德语"或"Deutsch",在法语系统中为法语"或"Francais"等.

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?

谢谢!

推荐答案

要确定系统上的当前语言,您可以查看以下环境变量(按优先级从高到低排序):

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_MESSAGESLC_NUMERICLC_TIMELC_COLLATE
  4. LANG
  1. LANGUAGE
  2. LC_ALL
  3. LC_MESSAGES, LC_NUMERIC, LC_TIME, LC_COLLATE, and others
  4. LANG

每个变量都有一种特殊格式: ll_CC ,其中前两个字母表示语言代码,后两个字母表示国家代码.还可以指定其他信息,例如字符集或变量.作为例外,第一个变量可以包含语言代码列表,并且只有在启用了本地化机制后,该变量才起作用.

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.

至少, gettext 是类Unix操作系统中最流行的翻译框架,受这些规则的约束.
https://gnu.org/software/gettext/manual/html_node/gettext_2.html#Locale-Environment-Variables

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

这篇关于找出Linux上的默认语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆