diff --git a/src/LocalizationData.cpp b/src/LocalizationData.cpp index a39200f..0a5ae25 100644 --- a/src/LocalizationData.cpp +++ b/src/LocalizationData.cpp @@ -78,37 +78,44 @@ void LocalizationData::WriteToFile(const std::filesystem::path& path) { tempFilesPositions[file.first] = p1; } outFile << "ENDDATA" << std::endl; + + size_t numberGlobal = 0; // actual localization for (const auto& file : _globalFiles) { auto pos = outFile.tellp(); for (const auto& kv : file.second.GetMap()) { outFile << kv.first << "|" << kv.second << std::endl; + numberGlobal++; } auto end = outFile.tellp(); auto length = end - pos; auto data = globalFilesPositions[file.first]; outFile.seekp(data); - outFile << std::setfill ('0') << std::setw(4) << std::hex << pos; + outFile << std::setfill('0') << std::setw(4) << std::hex << pos; outFile << "~"; - outFile << std::setfill ('0') << std::setw(4) << std::hex << length; + outFile << std::setfill('0') << std::setw(4) << std::hex << length; outFile.seekp(end); } + + size_t numberTemp = 0; for (const auto& file : _tempFiles) { auto pos = outFile.tellp(); for (const auto& kv : file.second.GetMap()) { outFile << kv.first << "|" << kv.second << std::endl; + numberTemp++; } auto end = outFile.tellp(); auto length = end - pos; auto data = tempFilesPositions[file.first]; outFile.seekp(data); - outFile << std::setfill ('0') << std::setw(4) << std::hex << pos; + outFile << std::setfill('0') << std::setw(4) << std::hex << pos; outFile << "~"; - outFile << std::setfill ('0') << std::setw(4) << std::hex << length; + outFile << std::setfill('0') << std::setw(4) << std::hex << length; outFile.seekp(end); } outFile.close(); - std::cout << "Wrote language file to " << path << std::endl; + std::cout << "Wrote language file to " << path << ". Wrote " << numberGlobal << " global keys and " << numberTemp + << " temp keys." << std::endl; } diff --git a/src/LocalizationFile.cpp b/src/LocalizationFile.cpp index 134182a..13a97f8 100644 --- a/src/LocalizationFile.cpp +++ b/src/LocalizationFile.cpp @@ -1,6 +1,16 @@ #include "LocalizationFile.hpp" #include #include +#include + +const std::regex keyChecker = std::regex("[^a-z0-9_]+"); + +static bool IsKeyValid(const std::string_view & key){ + if (std::regex_search(key.begin(), key.end(), keyChecker)){ + return false; + } + return true; +} void LocalizationFile::LoadFile(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { @@ -33,6 +43,9 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) { std::getline(linestream, value, sep); if (key.empty()) continue; + if (!IsKeyValid(key)){ + std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl; + } _map[key] = value; } file.close();