如何在Linux中获取给定语言环境的语言名称
这几乎是这个问题,其中包含更多信息.我的目标是弄清楚系统中安装的语言.
This is pretty much This question with a bit more information. My goal is to work out the languages installed in the system.
以下命令
locale -a
显示所有语言(格式为en_AU.utf8).这似乎与/usr/lib/locale的内容相对应.
displays all the languages (in a format such as en_AU.utf8). This seems to correspond to the contents of /usr/lib/locale.
此外,调用
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).
这似乎是/usr/lib/locale/fr_FR.utf8/LC_IDENTIFICATION中包含的信息.
This seems to be the information contained in /usr/lib/locale/fr_FR.utf8/LC_IDENTIFICATION.
是否有一种方法(可能是API调用)来获取此信息?我查看了locale实用程序的来源,但它使用了私有结构.
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.
感谢Yasir.这正是我想要的:
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));
}