Name of user's language, in English

O

Ole Nielsby

Does C++ have a method of retrieving this?

When launching my app, I want to select the appropriate language
for ts GUI, based on the user's language setting.

The frameworks wxWidgets and OpenOffice UNO have this
functionality but the wxWidgets code is a mess of platform
specific #ifdef sections. I wonder i there is a standard compliant
way.

The locale functions help formatting numbers and currency but
they don't tell the language name AFAICanSee.

I looked in the Boost docs but didn't find it there.
 
A

Adem24

Ole Nielsby said:
Does C++ have a method of retrieving this?

When launching my app, I want to select the appropriate language
for ts GUI, based on the user's language setting.

What is ts ?
The frameworks wxWidgets and OpenOffice UNO have this
functionality but the wxWidgets code is a mess of platform
specific #ifdef sections. I wonder i there is a standard compliant way.

What do you mean by such a statement?
What is wxWidgets?
Since when has it become part of the language in discussion here (C++) ?
The locale functions help formatting numbers and currency but
they don't tell the language name AFAICanSee.

I looked in the Boost docs but didn't find it there.

And you are really a programmer? What language?
 
P

Pascal J. Bourguignon

Ole Nielsby said:
Does C++ have a method of retrieving this?

No. This is not a programming language question.

It would depend on the Operating System, and/or on the user interface
toolkit.
When launching my app, I want to select the appropriate language
for ts GUI, based on the user's language setting.

The frameworks wxWidgets and OpenOffice UNO have this
functionality but the wxWidgets code is a mess of platform
specific #ifdef sections. I wonder i there is a standard compliant
way.

The locale functions help formatting numbers and currency but
they don't tell the language name AFAICanSee.

I looked in the Boost docs but didn't find it there.

On unix systems, man 7 locale should give you enough information.
Namely, the unix user sets its language by setting environment
variables such as LANG, LANGUAGE, LC_ALL, LC_CTYPE, LC_COLLATE, etc.

Of course, naive users cannot understand what an environment variable
is, so GUI environments have their own way to do it. Read the
documentation.

If wxWidgets is a mess, I could advise you to use a better
environment, such as GNUstep.

In anycase, these it's iso639 language codes that must be put in these
environment variables, so if you want the name in English, you will
have to map it yourself.

This can be done with a std::map<std::string,std::string> iso636ToEnglishNames;
that you fill explicitely:

struct{ const char* englishName,
const char* code,
const char* family } iso636ToEnglishNamesData[]={
{"AYMARA","AY","AMERINDIAN"},
{"GUARANI","GN","AMERINDIAN"},
{"QUECHUA","QU","AMERINDIAN"},
{"BHUTANI","DZ","ASIAN"},
{"BURMESE","MY","ASIAN"},
{"CAMBODIAN","KM","ASIAN"},
{"CHINESE","ZH","ASIAN"},
{"JAPANESE","JA","ASIAN"},
{"KOREAN","KO","ASIAN"},
{"LAOTHIAN","LO","ASIAN"},
{"THAI","TH","ASIAN"},
{"TIBETAN","BO","ASIAN"},
{"VIETNAMESE","VI","ASIAN"},
{"LATVIAN","LV","BALTIC"},
{"LITHUANIAN","LT","BALTIC"},
{"BASQUE","EU","BASQUE"},
{"BRETON","BR","CELTIC"},
{"IRISH","GA","CELTIC"},
{"SCOTS-GAELIC","GD","CELTIC"},
{"WELSH","CY","CELTIC"},
{"KANNADA","KN","DRAVIDIAN"},
{"MALAYALAM","ML","DRAVIDIAN"},
{"TAMIL","TA","DRAVIDIAN"},
{"TELUGU","TE","DRAVIDIAN"},
{"GREENLANDIC","KL","ESKIMO"},
{"INUPIAK","IK","ESKIMO"},
{"ESTONIAN","ET","FINNO-UGRIC"},
{"FINNISH","FI","FINNO-UGRIC"},
{"HUNGARIAN","HU","FINNO-UGRIC"},
{"AFRIKAANS","AF","GERMANIC"},
{"DANISH","DA","GERMANIC"},
{"DUTCH","NL","GERMANIC"},
{"ENGLISH","EN","GERMANIC"},
{"FAROESE","FO","GERMANIC"},
{"FRISIAN","FY","GERMANIC"},
{"GERMAN","DE","GERMANIC"},
{"ICELANDIC","IS","GERMANIC"},
{"NORWEGIAN","NO","GERMANIC"},
{"SWEDISH","SV","GERMANIC"},
{"YIDDISH","YI","GERMANIC"},
{"AFAN","OM","HAMITIC"},
{"AFAR","AA","HAMITIC"},
{"SOMALI","SO","HAMITIC"},
{"ABKHAZIAN","AB","IBERO-CAUCASIAN"},
{"GEORGIAN","KA","IBERO-CAUCASIAN"},
{"ASSAMESE","AS","INDIAN"},
{"BENGALI","BN","INDIAN"},
{"BIHARI","BH","INDIAN"},
{"GUJARATI","GU","INDIAN"},
{"HINDI","HI","INDIAN"},
{"KASHMIRI","KS","INDIAN"},
{"MARATHI","MR","INDIAN"},
{"NEPALI","NE","INDIAN"},
{"ORIYA","OR","INDIAN"},
{"PUNJABI","PA","INDIAN"},
{"SANSKRIT","SA","INDIAN"},
{"SINDHI","SD","INDIAN"},
{"SINGHALESE","SI","INDIAN"},
{"URDU","UR","INDIAN"},
{"ALBANIAN","SQ","INDO-EUROPEAN/OTHER"},
{"ARMENIAN","HY","INDO-EUROPEAN/OTHER"},
{"ESPERANTO","EO","INTERNATIONAL"},
{"INTERLINGUA","IA","INTERNATIONAL"},
{"INTERLINGUE","IE","INTERNATIONAL"},
{"VOLAPUK","VO","INTERNATIONAL"},
{"KURDISH","KU","IRANIAN"},
{"PASHTO","PS","IRANIAN"},
{"PERSIAN","FA","IRANIAN"},
{"TAJIK","TG","IRANIAN"},
{"GREEK","EL","LATIN/GREEK"},
{"LATIN","LA","LATIN/GREEK"},
{"HAUSA","HA","NEGRO-AFRICAN"},
{"KINYARWANDA","RW","NEGRO-AFRICAN"},
{"KURUNDI","RN","NEGRO-AFRICAN"},
{"LINGALA","LN","NEGRO-AFRICAN"},
{"SANGHO","SG","NEGRO-AFRICAN"},
{"SESOTHO","ST","NEGRO-AFRICAN"},
{"SETSWANA","TN","NEGRO-AFRICAN"},
{"SHONA","SN","NEGRO-AFRICAN"},
{"SISWATI","SS","NEGRO-AFRICAN"},
{"SWAHILI","SW","NEGRO-AFRICAN"},
{"TSONGA","TS","NEGRO-AFRICAN"},
{"TWI","TW","NEGRO-AFRICAN"},
{"WOLOF","WO","NEGRO-AFRICAN"},
{"XHOSA","XH","NEGRO-AFRICAN"},
{"YORUBA","YO","NEGRO-AFRICAN"},
{"ZULU","ZU","NEGRO-AFRICAN"},
{"FIJI","FJ","OCEANIC/INDONESIAN"},
{"INDONESIAN","ID","OCEANIC/INDONESIAN"},
{"JAVANESE","JV","OCEANIC/INDONESIAN"},
{"MALAGASY","MG","OCEANIC/INDONESIAN"},
{"MALAY","MS","OCEANIC/INDONESIAN"},
{"MAORI","MI","OCEANIC/INDONESIAN"},
{"SAMOAN","SM","OCEANIC/INDONESIAN"},
{"SUNDANESE","SU","OCEANIC/INDONESIAN"},
{"TAGALOG","TL","OCEANIC/INDONESIAN"},
{"TONGA","TO","OCEANIC/INDONESIAN"},
{"CATALAN","CA","ROMANCE"},
{"CORSICAN","CO","ROMANCE"},
{"FRENCH","FR","ROMANCE"},
{"GALICIAN","GL","ROMANCE"},
{"ITALIAN","IT","ROMANCE"},
{"MOLDAVIAN","MO","ROMANCE"},
{"OCCITAN","OC","ROMANCE"},
{"PORTUGUESE","PT","ROMANCE"},
{"RHAETO-ROMANCE","RM","ROMANCE"},
{"ROMANIAN","RO","ROMANCE"},
{"SPANISH","ES","ROMANCE"},
{"AMHARIC","AM","SEMITIC"},
{"ARABIC","AR","SEMITIC"},
{"HEBREW","HE","SEMITIC"},
{"MALTESE","MT","SEMITIC"},
{"TIGRINYA","TI","SEMITIC"},
{"BULGARIAN","BG","SLAVIC"},
{"BYELORUSSIAN","BE","SLAVIC"},
{"CROATIAN","HR","SLAVIC"},
{"CZECH","CS","SLAVIC"},
{"MACEDONIAN","MK","SLAVIC"},
{"POLISH","PL","SLAVIC"},
{"RUSSIAN","RU","SLAVIC"},
{"SERBIAN","SR","SLAVIC"},
{"SERBO-CROATIAN","SH","SLAVIC"},
{"SLOVAK","SK","SLAVIC"},
{"SLOVENIAN","SL","SLAVIC"},
{"UKRAINIAN","UK","SLAVIC"},
{"AZERBAIJANI","AZ","TURKIC/ALTAIC"},
{"BASHKIR","BA","TURKIC/ALTAIC"},
{"KAZAKH","KK","TURKIC/ALTAIC"},
{"KIRGHIZ","KY","TURKIC/ALTAIC"},
{"TATAR","TT","TURKIC/ALTAIC"},
{"TURKISH","TR","TURKIC/ALTAIC"},
{"TURKMEN","TK","TURKIC/ALTAIC"},
{"UZBEK","UZ","TURKIC/ALTAIC"},
{"BISLAMA","BI","MISCELLANEOUS"},
{"MONGOLIAN","MN","MISCELLANEOUS"},
{"NAURU","NA","MISCELLANEOUS"},
};

std::map<std::string,std::string> iso636ToEnglishNames;
for(i=0;i<sizeof(iso636ToEnglishNamesData)/sizeof(iso636ToEnglishNamesData[0]);i++){
iso636ToEnglishNames[iso636ToEnglishNamesData.code]=iso636ToEnglishNamesData.name;
}

So you can get the English name of the user selected language with something like:

iso636ToEnglishNames[toUpperCase(extractLanguage(getenv("LANG")))];

Note, you can get an uptodate list from
http://www.loc.gov/standards/iso639-2/langhome.html
 
J

James Kanze

Does C++ have a method of retrieving this?

Retrieving what? What does the name of user's language mean?
What if there are a lot of users, with different languages?
(That's the case for most of my programs.)
When launching my app, I want to select the appropriate
language for ts GUI, based on the user's language setting.

Like most things which concern the GUI, it's implementation
dependent. Most likely, the GUI framework itself has something.
The frameworks wxWidgets and OpenOffice UNO have this
functionality but the wxWidgets code is a mess of platform
specific #ifdef sections. I wonder i there is a standard
compliant way.

Not really. You can do something like:
std::locale( "" ).name()
which should give you the name of the locale specific native
environment, whatever that means. (I'm pretty sure that the
intent is to give the login user's locale.) But I'm not sure
that's not necessarily much help, when it works, and with g++,
all it does is core dump anyway, at least under Solaris.
(Locale names aren't standardized.)
The locale functions help formatting numbers and currency but
they don't tell the language name AFAICanSee.

They're supposed to allow you to get locale dependent messages,
so if you use them to get the text you want to display, they
should work. In theory. You still have to figure out how to
install your messages (and their translations) as part of the
corresponding locales for each system. And from experience, I
wouldn't count on it working anyway.
I looked in the Boost docs but didn't find it there.

I don't think that Boost has much which concerns locales.
 
A

acehreli

What is ts ?
Irrelevant.


What do you mean by such a statement?

The OP is giving examples of some functionality and seeking it's
equivalent in standard C++.
What is wxWidgets?

A framework used as an example.
Since when has it become part of the language in discussion here (C++) ?

It is not a part of C++. It may have something to do with the part of
"such a statement" above that you admit did not understand.
And you are really a programmer? What language?

Boost is a collection of C++ libraries:

boost.org

By the way, I have a feeling that missed the point of your post; if
there was one that is...

Ali
 
O

Ole Nielsby

Pascal J. Bourguignon said:
In anycase, these it's iso639 language codes

James Kanze said:
You can do something like:
std::locale( "" ).name()
But [...] with g++, all it does is core dump anyway, at
least under Solaris.

Thanks for these hints. It seems I'll have to do without it.

(But I really think it belongs in a standard - perhaps in the
Boost locale library. It may be technically ill-defined by the
present state of things, but to the user, it's very well-defined.)
 
J

James Kanze

In anycase, these it's iso639 language codes
James Kanze said:
You can do something like:
std::locale( "" ).name()
But [...] with g++, all it does is core dump anyway, at
least under Solaris.
Thanks for these hints. It seems I'll have to do without it.
(But I really think it belongs in a standard - perhaps in the
Boost locale library. It may be technically ill-defined by the
present state of things, but to the user, it's very
well-defined.)

Is it? What's my "language", when I'm a user? On my Windows
machine at home, Windows itself displays the messages in French,
but the US keyboard driver is usually active, and different
programs display in different languages, depending on what I'm
doing at the moment. On the Unix machines, my LC_ variables are
mixed, and also depend on the system (since different systems
have different installed locales). What's my son's language,
when he's playing an online game with some of the participants
in Paris, and others in Frankfurt?

And of course, that C++ doesn't control everything; typically,
the information simply isn't available for the C++ library to
provide.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top