00001 // SuperTux 00002 // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de> 00003 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00004 // 00005 // This program is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 00018 #include "supertux/menu/language_menu.hpp" 00019 00020 extern "C" { 00021 #include <findlocale.h> 00022 } 00023 #include "gui/menu_item.hpp" 00024 #include "gui/menu_manager.hpp" 00025 #include "supertux/gameconfig.hpp" 00026 #include "supertux/globals.hpp" 00027 00028 enum { 00029 MNID_LANGUAGE_AUTO_DETECT = 0, 00030 MNID_LANGUAGE_ENGLISH = 1, 00031 MNID_LANGUAGE_NEXT = 10 00032 }; 00033 00034 LanguageMenu::LanguageMenu() 00035 { 00036 add_label(_("Language")); 00037 add_hl(); 00038 add_entry(MNID_LANGUAGE_AUTO_DETECT, _("<auto-detect>")); 00039 add_entry(MNID_LANGUAGE_ENGLISH, "English"); 00040 00041 int mnid = MNID_LANGUAGE_NEXT; 00042 std::set<tinygettext::Language> languages = dictionary_manager->get_languages(); 00043 for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++) 00044 { 00045 add_entry(mnid++, i->get_name()); 00046 } 00047 00048 add_hl(); 00049 add_back(_("Back")); 00050 } 00051 00052 void 00053 LanguageMenu::menu_action(MenuItem* item) 00054 { 00055 if (item->id == MNID_LANGUAGE_AUTO_DETECT) // auto detect 00056 { 00057 FL_Locale *locale; 00058 FL_FindLocale(&locale, FL_MESSAGES); 00059 tinygettext::Language language = tinygettext::Language::from_spec( locale->lang?locale->lang:"", locale->country?locale->country:"", locale->variant?locale->variant:""); 00060 FL_FreeLocale(&locale); 00061 00062 dictionary_manager->set_language(language); // set currently detected language 00063 g_config->locale = ""; // do auto detect every time on startup 00064 g_config->save(); 00065 MenuManager::pop_current(); 00066 } 00067 else if (item->id == MNID_LANGUAGE_ENGLISH) // english 00068 { 00069 g_config->locale = "en"; 00070 dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); 00071 g_config->save(); 00072 MenuManager::pop_current(); 00073 } 00074 else 00075 { 00076 int mnid = MNID_LANGUAGE_NEXT; 00077 std::set<tinygettext::Language> languages = dictionary_manager->get_languages(); 00078 00079 for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++) 00080 { 00081 if (item->id == mnid++) 00082 { 00083 g_config->locale = i->str(); 00084 dictionary_manager->set_language(*i); 00085 g_config->save(); 00086 MenuManager::pop_current(); 00087 break; 00088 } 00089 } 00090 } 00091 } 00092 00093 /* EOF */