yWeb: write missing translations to file

This commit is contained in:
GetAway
2018-12-01 17:50:33 +01:00
parent 2bd937a0d0
commit 61aeeb1537
2 changed files with 35 additions and 1 deletions

View File

@@ -9,6 +9,9 @@
#include <cstdlib>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <system/helpers.h>
// yhttpd
@@ -103,10 +106,40 @@ std::string CLanguage::getTranslation(std::string id){
trans=NeutrinoLanguage->getString(id,"");
if(trans.empty())
trans=DefaultLanguage->getString(id,"");
if (trans.empty())
if (trans.empty()) {
write_missing_trans(id);
trans = "# " + id + " #";
}
return trans;
}
void CLanguage::write_missing_trans(std::string const& entry)
{
std::string file = "/tmp/yweb.missing.translation";
std::ifstream in;
std::ofstream out;
std::string line;
bool found = false;
in.open(file, std::ios::in);
if(in.is_open())
{
while (std::getline(in, line) && !found)
{
if (line.compare(entry) == 0)
found = true;
}
in.close();
}
if (!found)
{
out.open(file, std::ios::out|std::ios::app);
if (out.is_open())
{
out << entry << std::endl;
out.close();
}
}
}
//-----------------------------------------------------------------------------
// Find language directory
//-----------------------------------------------------------------------------

View File

@@ -40,6 +40,7 @@ class CLanguage
std::string getLanguageDir(void);
std::string getTranslation(std::string id);
void write_missing_trans(std::string const& entry);
};
#endif /* __yttpd_language_h__ */