From 40f984d967fff71f837ccd56a55458a5f584d9be Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Oct 2010 19:03:39 +0200 Subject: [PATCH] Changed: #1129 Implement missing CI18N::getLanguageCodes and CI18N::getLanguageNames methods --- code/nel/include/nel/misc/i18n.h | 6 ++--- code/nel/src/misc/i18n.cpp | 41 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/code/nel/include/nel/misc/i18n.h b/code/nel/include/nel/misc/i18n.h index c3972c088..6778efcc6 100644 --- a/code/nel/include/nel/misc/i18n.h +++ b/code/nel/include/nel/misc/i18n.h @@ -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 _LanguageCodes; + static std::vector _LanguageNames; - static bool _LanguagesNamesLoaded; + static bool _LanguagesNamesLoaded; static std::string _SelectedLanguageCode; static const ucstring _NotTranslatedValue; diff --git a/code/nel/src/misc/i18n.cpp b/code/nel/src/misc/i18n.cpp index 093da073a..94e41a06a 100644 --- a/code/nel/src/misc/i18n.cpp +++ b/code/nel/src/misc/i18n.cpp @@ -31,13 +31,52 @@ const ucstring CI18N::_NotTranslatedValue(""); bool CI18N::_LanguagesNamesLoaded = false; string CI18N::_SelectedLanguageCode; CI18N::ILoadProxy *CI18N::_LoadProxy = 0; - +vector CI18N::_LanguageCodes; +vector CI18N::_LanguageNames; void CI18N::setLoadProxy(ILoadProxy *loadProxy) { _LoadProxy = loadProxy; } +const std::vector &CI18N::getLanguageNames() +{ + return _LanguageNames; +} + +const std::vector &CI18N::getLanguageCodes() +{ + if (!_LanguagesNamesLoaded) + { + std::vector 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 ();