Re: Name of user's language, in English
"Ole Nielsby" <ole.nielsby@tekareyouspamminglogisk.dk> writes:
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[i].code]=iso636ToEnglishNamesData[i].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
--
__Pascal Bourguignon__