src/tinygettext/findlocale.hpp File Reference

Go to the source code of this file.

Classes

struct  FL_Locale

Typedefs

typedef const char * FL_Lang
typedef const char * FL_Country
typedef const char * FL_Variant

Enumerations

enum  FL_Success { FL_FAILED = 0, FL_DEFAULT_GUESS = 1, FL_CONFIDENT = 2 }
enum  FL_Domain { FL_MESSAGES = 0 }

Functions

FL_Success FL_FindLocale (FL_Locale **locale, FL_Domain domain)
void FL_FreeLocale (FL_Locale **locale)


Typedef Documentation

typedef const char* FL_Country

Definition at line 34 of file findlocale.hpp.

typedef const char* FL_Lang

Definition at line 33 of file findlocale.hpp.

typedef const char* FL_Variant

Definition at line 35 of file findlocale.hpp.


Enumeration Type Documentation

enum FL_Domain

Enumerator:
FL_MESSAGES 

Definition at line 52 of file findlocale.hpp.

00052              {
00053   FL_MESSAGES = 0
00054 } FL_Domain;

enum FL_Success

Enumerator:
FL_FAILED 
FL_DEFAULT_GUESS 
FL_CONFIDENT 

Definition at line 43 of file findlocale.hpp.

00043              {
00044   /* for some reason we failed to even guess: this should never happen */
00045   FL_FAILED        = 0,
00046   /* couldn't query locale -- returning a guess (almost always English) */
00047   FL_DEFAULT_GUESS = 1,
00048   /* the returned locale type was found by successfully asking the system */
00049   FL_CONFIDENT     = 2
00050 } FL_Success;


Function Documentation

FL_Success FL_FindLocale ( FL_Locale **  locale,
FL_Domain  domain 
)

Definition at line 453 of file findlocale.cpp.

References accumulate_env(), accumulate_locstring(), canonize_fl(), FL_Locale::country, FL_CONFIDENT, FL_DEFAULT_GUESS, FL_FAILED, FL_Locale::lang, and FL_Locale::variant.

Referenced by TinyGetText::DictionaryManager::DictionaryManager(), Main::init_tinygettext(), and LanguageMenu::menu_action().

00453                                                         {
00454   FL_Success success = FL_FAILED;
00455   FL_Locale *rtn = (FL_Locale*) malloc(sizeof(FL_Locale));
00456   rtn->lang = NULL;
00457   rtn->country = NULL;
00458   rtn->variant = NULL;
00459 
00460 #ifdef WIN32
00461   /* win32 >= mswindows95 */
00462   {
00463     LCID lcid = GetThreadLocale();
00464     if (lcid_to_fl(lcid, rtn)) {
00465       success = FL_CONFIDENT;
00466     }
00467     if (success == FL_FAILED) {
00468       /* assume US English on mswindows systems unless we know otherwise */
00469       if (accumulate_locstring("en_US.ISO_8859-1", rtn)) {
00470         success = FL_DEFAULT_GUESS;
00471       }
00472     }
00473   }
00474 #else
00475   /* assume unixoid */
00476   {
00477 #ifdef MACOSX
00478     CFIndex sz;
00479     CFArrayRef languages;
00480     CFStringRef uxstylelangs;
00481     char *uxsl;
00482 
00483     /* get the languages from the user's presets */
00484     languages = (CFArrayRef)CFPreferencesCopyValue(CFSTR("AppleLanguages"),
00485       kCFPreferencesAnyApplication, kCFPreferencesCurrentUser,
00486       kCFPreferencesAnyHost);
00487 
00488     /* join the returned string array into a string separated by colons */
00489     uxstylelangs = CFStringCreateByCombiningStrings(kCFAllocatorDefault,
00490       languages, CFSTR(":"));
00491 
00492     /* convert this string into a C string */
00493     sz = CFStringGetLength(uxstylelangs) + 1;
00494     uxsl = (char*)malloc(sz);
00495     CFStringGetCString(uxstylelangs, uxsl, sz, kCFStringEncodingISOLatin1);
00496 
00497     /* add it to the list */
00498     if (accumulate_locstring(uxsl, rtn)) {
00499       success = FL_CONFIDENT;
00500     }
00501     /* continue the UNIX method */
00502 #endif
00503     /* examples: */
00504     /* sv_SE.ISO_8859-1 */
00505     /* fr_FR.ISO8859-1 */
00506     /* no_NO_NB */
00507     /* no_NO_NY */
00508     /* no_NO */
00509     /* de_DE */
00510     /* try the various vars in decreasing order of authority */
00511     if (accumulate_env("LC_ALL", rtn) ||
00512         accumulate_env("LC_MESSAGES", rtn) ||
00513         accumulate_env("LANG", rtn) ||
00514         accumulate_env("LANGUAGE", rtn)) {
00515       success = FL_CONFIDENT;
00516     }
00517     if (success == FL_FAILED) {
00518       /* assume US English on unixoid systems unless we know otherwise */
00519       if (accumulate_locstring("en_US.ISO_8859-1", rtn)) {
00520         success = FL_DEFAULT_GUESS;
00521       }
00522     }
00523   }
00524 #endif
00525 
00526   if (success != FL_FAILED) {
00527     canonize_fl(rtn);
00528   }
00529 
00530   *locale = rtn;
00531   return success;
00532 }

void FL_FreeLocale ( FL_Locale **  locale  ) 

Definition at line 536 of file findlocale.cpp.

References FL_Locale::country, FL_Locale::lang, and FL_Locale::variant.

Referenced by TinyGetText::DictionaryManager::DictionaryManager(), Main::init_tinygettext(), and LanguageMenu::menu_action().

00536                                   {
00537   if (locale) {
00538     FL_Locale *l = *locale;
00539     if (l) {
00540       if (l->lang) {
00541         free((void*)l->lang);
00542       }
00543       if (l->country) {
00544         free((void*)l->country);
00545       }
00546       if (l->variant) {
00547         free((void*)l->variant);
00548       }
00549       free(l);
00550       *locale = NULL;
00551     }
00552   }
00553 }


Generated on Mon Jun 9 03:38:27 2014 for SuperTux by  doxygen 1.5.1