如何在 linux 中获取给定语言环境的语言名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4894232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Howto get the language name for a given locale in linux
提问by Dushara
This is pretty much This questionwith a bit more information. My goal is to work out the languages installed in the system.
这几乎是这个问题,有更多信息。我的目标是找出系统中安装的语言。
The following command
以下命令
locale -a
displays all the languages (in a format such as en_AU.utf8). This seems to correspond to the contents of /usr/lib/locale.
显示所有语言(以 en_AU.utf8 等格式)。这似乎对应于 /usr/lib/locale 的内容。
Furthermore, invoking
此外,调用
LANG=fr_FR.utf8 locale -ck LC_IDENTIFICATION
Gives information of that particular locale which includes the language name (Which in this case is French).
提供该特定语言环境的信息,其中包括语言名称(在本例中为法语)。
This seems to be the information contained in /usr/lib/locale/fr_FR.utf8/LC_IDENTIFICATION.
这似乎是/usr/lib/locale/fr_FR.utf8/LC_IDENTIFICATION 中包含的信息。
Is there a way (maybe an API call) to obtain this info? I looked at the source of the locale utility but it uses a private struct.
有没有办法(也许是 API 调用)来获取这些信息?我查看了 locale 实用程序的源代码,但它使用了私有结构。
采纳答案by Dushara
Thanks to Yasir. This is exactly what I wanted:
感谢亚西尔。这正是我想要的:
#include <langinfo.h>
char *s;
s = getenv("LANG");
if (s == NULL)
printf("LANG is not set");
else {
setlocale(LC_ALL, s);
printf(nl_langinfo(_NL_IDENTIFICATION_LANGUAGE));
}