2 // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "supertux/language_menu.hpp"
21 #include "findlocale.h"
23 #include "gui/menu_item.hpp"
24 #include "supertux/gameconfig.hpp"
27 MNID_LANGUAGE_AUTO_DETECT = 0,
28 MNID_LANGUAGE_ENGLISH = 1,
29 MNID_LANGUAGE_NEXT = 10
32 LanguageMenu::LanguageMenu()
34 add_label(_("Language"));
36 add_entry(MNID_LANGUAGE_AUTO_DETECT, _("<auto-detect>"));
37 add_entry(MNID_LANGUAGE_ENGLISH, "English");
39 int mnid = MNID_LANGUAGE_NEXT;
40 std::set<tinygettext::Language> languages = dictionary_manager.get_languages();
41 for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++)
43 add_entry(mnid++, i->get_name());
51 LanguageMenu::menu_action(MenuItem* item)
53 if (item->id == MNID_LANGUAGE_AUTO_DETECT) // auto detect
56 FL_FindLocale(&locale, FL_MESSAGES);
57 tinygettext::Language language = tinygettext::Language::from_spec(locale->lang, locale->country, locale->variant);
58 FL_FreeLocale(&locale);
60 dictionary_manager.set_language(language);
61 g_config->locale = language.str();
65 else if (item->id == MNID_LANGUAGE_ENGLISH) // english
67 g_config->locale = "en";
68 dictionary_manager.set_language(tinygettext::Language::from_name(g_config->locale));
74 int mnid = MNID_LANGUAGE_NEXT;
75 std::set<tinygettext::Language> languages = dictionary_manager.get_languages();
77 for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++)
79 if (item->id == mnid++)
81 g_config->locale = i->str();
82 dictionary_manager.set_language(*i);