Beispiel #1
0
std::string getUserLanguage() {
    const char* pLang = NULL;

    fprintf(stdout,"Detecting locale...\t\t"); fflush(stdout);

#if defined (_WIN32)
    char ISO639_LanguageName[10];
    if(GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, ISO639_LanguageName, sizeof(ISO639_LanguageName)) == 0) {
        return "";
    } else {

        pLang = ISO639_LanguageName;
    }

#elif defined (__APPLE__)
	pLang = getMacLanguage();
	if(pLang == NULL) {
        return "";
	}

#else
    // should work on most unices
	pLang = getenv("LC_ALL");
    if(pLang == NULL) {
		// try LANG
		pLang = getenv("LANG");
        if(pLang == NULL) {
			return "";
		}
    }
#endif

    fprintf(stderr, "'%s'\n", pLang); fflush(stdout);

    if(strlen(pLang) < 2) {
        return "";
    } else {
        return strToLower(std::string(pLang, 2));
    }
}
int GetUserLanguage() {
    const char* pLang = NULL;

#if defined (_WIN32)
    char ISO639_LanguageName[10];
    if(GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, ISO639_LanguageName, sizeof(ISO639_LanguageName)) == 0) {
        return LNG_UNKNOWN;
    } else {
        pLang = ISO639_LanguageName;
    }

#elif defined (__APPLE__)
	pLang = getMacLanguage();
	if(pLang == NULL) {
        return LNG_UNKNOWN;
	}

#else
    // should work most unices
	pLang = getenv("LC_ALL");
    if(pLang == NULL) {
		// try LANG
		pLang = getenv("LANG");
        if(pLang == NULL) {
			return LNG_UNKNOWN;
		}
    }
#endif

    if((pLang[0] == 'f' || pLang[0] == 'F') && (pLang[1] == 'r' || pLang[1] == 'R')) {
        return LNG_FRE;
    } else if((pLang[0] == 'd' || pLang[0] == 'D') && (pLang[1] == 'e' || pLang[1] == 'E')) {
        return LNG_GER;
    } else if((pLang[0] == 'e' || pLang[0] == 'E') && (pLang[1] == 'n' || pLang[1] == 'N')) {
        return LNG_ENG;
    } else {
        return LNG_UNKNOWN;
    }
}