How to get the language name for a given language in Linux

This is pretty much this question with a bit more information. My goal is to develop the languages ​​installed in the system.

Next command

locale -a 

displays all languages ​​(in a format such as en_AU.utf8). This seems to match the contents of / usr / lib / locale.

Also causing

LANG=fr_FR.utf8 locale -ck LC_IDENTIFICATION

Provides information about that particular locale that includes the name of the language (which in this case is French).

This seems to be the information contained in / usr / lib / locale / fr _FR.utf8 / LC_IDENTIFICATION.

Is there a way (maybe an API call) to get this information? I looked at the source of the locale utility, but it uses a private structure.

+5
source share
2

. , :

#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));
}
0

, , , , getenv(3), , e. :.

char *s;
s = getenv("LANG");
if (s == NULL) 
    printf("LANG is not set");
else
    printf(s);
+1

All Articles