bool LLAppViewerLinux::initParseCommandLine(LLCommandLineParser& clp) { if (!clp.parseCommandLine(gArgC, gArgV)) { return false; } // Find the system language. FL_Locale *locale = NULL; FL_Success success = FL_FindLocale(&locale, FL_MESSAGES); if (success != 0) { if (success >= 2 && locale->lang) // confident! { LL_INFOS("AppInit") << "Language " << ll_safe_string(locale->lang) << LL_ENDL; LL_INFOS("AppInit") << "Location " << ll_safe_string(locale->country) << LL_ENDL; LL_INFOS("AppInit") << "Variant " << ll_safe_string(locale->variant) << LL_ENDL; LLControlVariable* c = gSavedSettings.getControl("SystemLanguage"); if(c) { c->setValue(std::string(locale->lang), false); } } } FL_FreeLocale(&locale); return true; }
void Main::init_tinygettext() { g_dictionary_manager.reset(new tinygettext::DictionaryManager(std::unique_ptr<tinygettext::FileSystem>(new PhysFSFileSystem), "UTF-8")); tinygettext::Log::set_log_info_callback(log_info_callback); tinygettext::Log::set_log_warning_callback(log_warning_callback); tinygettext::Log::set_log_error_callback(log_error_callback); g_dictionary_manager->add_directory("locale"); // Config setting "locale" overrides language detection if (g_config->locale != "") { g_dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); } else { FL_Locale *locale; FL_FindLocale(&locale); tinygettext::Language language = tinygettext::Language::from_spec( locale->lang?locale->lang:"", locale->country?locale->country:"", locale->variant?locale->variant:""); FL_FreeLocale(&locale); g_dictionary_manager->set_language(language); } }
/** * @brief Attempts to detect the system language unless cl_lang was already set. * Then loads the PO file containing translated strings. */ void I18N_Init(void) { FL_Locale *locale; std::set<tinygettext::Language> languages; std::set<tinygettext::Language> languages_mod; cl_lang = Cvar_Get("cl_lang", "en", CVAR_ARCHIVE | CVAR_LATCH); cl_langDebug = Cvar_Get("cl_langDebug", "0", CVAR_ARCHIVE); tinygettext::Log::set_log_error_callback(&Tinygettext_Error); tinygettext::Log::set_log_info_callback(&Tinygettext_Info); tinygettext::Log::set_log_warning_callback(&Tinygettext_Warning); FL_FindLocale(&locale); // Do not change the language if it is already set if (!cl_lang->string[0]) { // locale->country is also supported for 'en_US' format if (locale->lang && locale->lang[0]) { Cvar_Set("cl_lang", va("%s", locale->lang)); } else { // Language detection failed. Fallback to English Cvar_Set("cl_lang", "en"); } } dictionary.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem)); dictionary_mod.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem)); dictionary.add_directory("locale/client"); dictionary_mod.add_directory("locale/mod"); languages = dictionary.get_languages(); Com_Printf("Available client translations:"); for (std::set<tinygettext::Language>::iterator p = languages.begin(); p != languages.end(); p++) { Com_Printf(" %s", p->get_name().c_str()); } Com_Printf("\n"); languages_mod = dictionary_mod.get_languages(); Com_Printf("Available mod translations:"); for (std::set<tinygettext::Language>::iterator p = languages_mod.begin(); p != languages_mod.end(); p++) { Com_Printf(" %s", p->get_name().c_str()); } Com_Printf("\n"); I18N_SetLanguage(cl_lang->string); FL_FreeLocale(&locale); }
void LanguageMenu::menu_action(MenuItem* item) { if (item->id == MNID_LANGUAGE_AUTO_DETECT) // auto detect { FL_Locale *locale; FL_FindLocale(&locale); tinygettext::Language language = tinygettext::Language::from_spec( locale->lang?locale->lang:"", locale->country?locale->country:"", locale->variant?locale->variant:""); FL_FreeLocale(&locale); dictionary_manager->set_language(language); // set currently detected language g_config->locale = ""; // do auto detect every time on startup g_config->save(); MenuManager::pop_current(); } else if (item->id == MNID_LANGUAGE_ENGLISH) // english { g_config->locale = "en"; dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); g_config->save(); MenuManager::pop_current(); } else { int mnid = MNID_LANGUAGE_NEXT; std::set<tinygettext::Language> languages = dictionary_manager->get_languages(); for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++) { if (item->id == mnid++) { g_config->locale = i->str(); dictionary_manager->set_language(*i); g_config->save(); MenuManager::pop_current(); break; } } } }