Make list of languages installed discoverable at runtime.

Stop hardcoding Russian in webadmin.
Limit the setting in controlpanel to the known languages, because
untrusted language code might lead to some interesting vulnerabilities.
This commit is contained in:
Alexey Sokolov
2017-08-19 18:05:47 +01:00
parent 328461faf1
commit f885699d1a
6 changed files with 65 additions and 8 deletions
+25
View File
@@ -15,11 +15,36 @@
*/
#include <znc/Translation.h>
#include <znc/FileUtils.h>
#ifdef HAVE_I18N
#include <boost/locale.hpp>
#endif
namespace {
std::map<CString, CTranslationInfo> FillTranslations() {
std::map<CString, CTranslationInfo> mTranslations;
CDir Dir;
Dir.Fill(_DATADIR_ "/translations");
for (CFile* pFile : Dir) {
CString sName = pFile->GetShortName();
CTranslationInfo& translation = mTranslations[sName];
MCString msData;
// TODO: make the file format more sensible than this
msData.ReadFromDisk(pFile->GetLongName());
translation.sSelfName = msData["SelfName"];
// TODO: right-to-left support
}
return mTranslations;
}
} // namespace
std::map<CString, CTranslationInfo> CTranslationInfo::GetTranslations() {
static std::map<CString, CTranslationInfo> mTranslations =
FillTranslations();
return mTranslations;
}
CTranslation& CTranslation::Get() {
static CTranslation translation;
return translation;