Split supertux/options_menu.?pp
[supertux.git] / src / supertux / language_menu.cpp
1 //  SuperTux
2 //  Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
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.
9 //
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.
14 //
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/>.
17
18 #include "supertux/language_menu.hpp"
19
20 #include "gui/menu_item.hpp"
21 #include "supertux/gameconfig.hpp"
22
23 LanguageMenu::LanguageMenu() 
24 {
25   add_label(_("Language"));
26   add_hl();
27   add_entry(0, std::string("<")+_("auto-detect")+">");
28   add_entry(1, "English");
29
30   int mnid = 10;    
31   std::set<std::string> languages = dictionary_manager.get_languages();
32   for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
33     std::string locale_name = *i;
34     TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
35     std::string locale_fullname = locale_name;
36     if (std::string(ldef.code) == locale_name) {
37       locale_fullname = ldef.name;
38     }
39     add_entry(mnid++, locale_fullname);
40   } 
41
42   add_hl();
43   add_back(_("Back"));
44 }
45
46 void
47 LanguageMenu::menu_action(MenuItem* item) 
48 {
49   if (item->id == 0) {
50     g_config->locale = "";
51     dictionary_manager.set_language(g_config->locale);
52     g_config->save();
53     Menu::pop_current();
54   }
55   else if (item->id == 1) {
56     g_config->locale = "en";
57     dictionary_manager.set_language(g_config->locale);
58     g_config->save();
59     Menu::pop_current();
60   }
61   int mnid = 10;    
62   std::set<std::string> languages = dictionary_manager.get_languages();
63   for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
64     std::string locale_name = *i;
65     if (item->id == mnid++) {
66       g_config->locale = locale_name;
67       dictionary_manager.set_language(g_config->locale);
68       g_config->save();
69       Menu::pop_current();
70     }
71   }
72 }
73
74 /* EOF */