Changed: #1129 Implement missing CI18N::getLanguageCodes and CI18N::getLanguageNames methods

This commit is contained in:
kervala 2010-10-14 19:03:39 +02:00
parent 587320aa0f
commit 40f984d967
2 changed files with 43 additions and 4 deletions

View file

@ -218,10 +218,10 @@ private:
// the alternative language that will be used if the sentence is not found in the original language
static StrMapContainer _StrMapFallback;
static const std::string _LanguageCodes[];
static const uint _NbLanguages;
static std::vector<std::string> _LanguageCodes;
static std::vector<ucstring> _LanguageNames;
static bool _LanguagesNamesLoaded;
static bool _LanguagesNamesLoaded;
static std::string _SelectedLanguageCode;
static const ucstring _NotTranslatedValue;

View file

@ -31,13 +31,52 @@ const ucstring CI18N::_NotTranslatedValue("<Not Translated>");
bool CI18N::_LanguagesNamesLoaded = false;
string CI18N::_SelectedLanguageCode;
CI18N::ILoadProxy *CI18N::_LoadProxy = 0;
vector<string> CI18N::_LanguageCodes;
vector<ucstring> CI18N::_LanguageNames;
void CI18N::setLoadProxy(ILoadProxy *loadProxy)
{
_LoadProxy = loadProxy;
}
const std::vector<ucstring> &CI18N::getLanguageNames()
{
return _LanguageNames;
}
const std::vector<std::string> &CI18N::getLanguageCodes()
{
if (!_LanguagesNamesLoaded)
{
std::vector<std::string> files;
// search all .uxt files
CPath::getFileList("uxt", files);
// if not uxt found, use default languages
if (files.empty())
{
_LanguageCodes.clear();
_LanguageCodes.push_back("en");
_LanguageCodes.push_back("fr");
_LanguageCodes.push_back("de");
_LanguageCodes.push_back("ru");
}
else
{
// add all languages found
for(uint i = 0; i < files.size(); ++i)
{
_LanguageCodes.push_back(toLower(CFile::getFilenameWithoutExtension(files[i])));
}
_LanguagesNamesLoaded = true;
}
}
return _LanguageCodes;
}
void CI18N::load (const string &languageCode, const string &fallbackLanguageCode)
{
if (_StrMapLoaded) _StrMap.clear ();