diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 6cfa4d1ea..1c0a28acb 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -21,6 +21,7 @@ #include #include "guiengine/scalable_font.hpp" +#include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" @@ -174,12 +175,21 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, cons m_lang_popup->add(); m_lang_popup->m_properties[PROP_ID] = "language_popup"; + + const std::vector* lang_list = translations->getLanguageList(); + const int amount = lang_list->size(); + for (int n=0; naddItem((*lang_list)[n], core::stringw((*lang_list)[n].c_str())); + } + /* m_lang_popup->addItem("en", L"English"); m_lang_popup->addItem("zh_CN", L"Chinese"); m_lang_popup->addItem("ru", L"Russian"); m_lang_popup->addItem("fr", L"French"); m_lang_popup->addItem("he", L"Hebrew"); - + */ manualAddWidget(m_lang_popup); m_lang_popup->setFocusForPlayer(PLAYER_ID_GAME_MASTER); diff --git a/src/utils/translation.cpp b/src/utils/translation.cpp index a68a112dd..cea361405 100644 --- a/src/utils/translation.cpp +++ b/src/utils/translation.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "irrlicht.h" @@ -46,18 +47,50 @@ // set to 1 to debug i18n #define TRANSLATE_VERBOSE 0 -Translations* translations=NULL; -bool remove_bom = false; +Translations* translations = NULL; +const bool REMOVE_BOM = false; #ifdef LINUX // m_debug #define PACKAGE "supertuxkart" #endif +/** The list of available languages; this is global so that it is cached (and remains + even if the translations object is deleted and re-created) */ +std::vector g_language_list; + +// Note : this method is not static because 'g_language_list' is initialized +// the first time Translations is constructed (despite being a global) +const std::vector* Translations::getLanguageList() const +{ + return &g_language_list; +} + // ---------------------------------------------------------------------------- Translations::Translations() { #ifdef ENABLE_NLS + if (g_language_list.size() == 0) + { + std::set flist; + file_manager->listFiles(flist, + file_manager->getTranslationDir(), + true); + + // English is always there but won't be found on file system + g_language_list.push_back("en"); + + std::set::iterator it; + for ( it=flist.begin() ; it != flist.end(); it++ ) + { + if (file_manager->fileExists(file_manager->getTranslationDir() + "/" + (*it).c_str() + "/LC_MESSAGES/supertuxkart.mo")) + { + g_language_list.push_back( *it ); + // printf("Lang : <%s>\n", (*it).c_str()); + } + } + } + // LC_ALL does not work, sscanf will then not always be able // to scan for example: s=-1.1,-2.3,-3.3 correctly, which is // used in driveline files. @@ -165,7 +198,7 @@ const wchar_t* Translations::w_gettext(const char* original) //for (int n=0;; n+=4) wchar_t* out_ptr = (wchar_t*)original_t; - if (remove_bom) out_ptr++; + if (REMOVE_BOM) out_ptr++; #if TRANSLATE_VERBOSE std::wcout << L" translation : " << out_ptr << std::endl; diff --git a/src/utils/translation.hpp b/src/utils/translation.hpp index 8f109c777..386bd8a7c 100644 --- a/src/utils/translation.hpp +++ b/src/utils/translation.hpp @@ -21,6 +21,7 @@ #define TRANSLATION_HPP #include "irrlicht.h" +#include #if ENABLE_NLS # ifdef __APPLE__ @@ -51,6 +52,8 @@ public: Translations(); const wchar_t *w_gettext(const char* original); bool isRTLLanguage() const; + + const std::vector* getLanguageList() const; }; // Translations