Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto get the language name for a given locale in linux

Tags:

linux

locale

This is pretty much This question with 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.

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.

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.

like image 845
Dushara Avatar asked Feb 04 '11 03:02

Dushara


People also ask

How do I find my locale Linux?

How to View System Locale in Linux. To view information about the current installed locale, use the locale or localectl utility. You can view more information about an environmental variable, for example LC_TIME, which stores the time and date format.

What command shows the list of locale variables?

To display the current character set for the locale, use locale -c charmap.

What is my locale setting?

The locale setting defines the language of your user interface and the display formats for information like time, date, and currency.

What is Lc_all locale?

Answer. The LC_ALL variable sets all locale variables output by the command 'locale -a'. It is a convenient way of specifying a language environment with one variable, without having to specify each LC_* variable. Processes launched in that environment will run in the specified locale.


1 Answers

I think, you could just get environment variables, using, for example, getenv(3), thus you would want to pass it the name of variable, e. g.:

char *s;
s = getenv("LANG");
if (s == NULL) 
    printf("LANG is not set");
else
    printf(s);
like image 79
YasirA Avatar answered Sep 30 '22 16:09

YasirA