如何在Linux中获取给定语言环境的语言名称 [英] Howto get the language name for a given locale in linux

查看:43
本文介绍了如何在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));
}

这篇关于如何在Linux中获取给定语言环境的语言名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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