Retrieve language list by scanning the /data/po dir

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7428 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-01-15 21:20:10 +00:00
parent 9dc6c082d3
commit 5f4e34328b
3 changed files with 50 additions and 4 deletions

View File

@ -21,6 +21,7 @@
#include <string>
#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<std::string>* lang_list = translations->getLanguageList();
const int amount = lang_list->size();
for (int n=0; n<amount; n++)
{
// TODO: retrieve a nice name for each language instead of displaying the language code
m_lang_popup->addItem((*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);

View File

@ -33,6 +33,7 @@
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#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<std::string> 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<std::string>* Translations::getLanguageList() const
{
return &g_language_list;
}
// ----------------------------------------------------------------------------
Translations::Translations()
{
#ifdef ENABLE_NLS
if (g_language_list.size() == 0)
{
std::set<std::string> 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<std::string>::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;

View File

@ -21,6 +21,7 @@
#define TRANSLATION_HPP
#include "irrlicht.h"
#include <vector>
#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<std::string>* getLanguageList() const;
}; // Translations