Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
d7beb77f1d
|
|||
|
ee85947c4c
|
|||
|
a56ccf68ec
|
@@ -78,37 +78,44 @@ void LocalizationData::WriteToFile(const std::filesystem::path& path) {
|
|||||||
tempFilesPositions[file.first] = p1;
|
tempFilesPositions[file.first] = p1;
|
||||||
}
|
}
|
||||||
outFile << "ENDDATA" << std::endl;
|
outFile << "ENDDATA" << std::endl;
|
||||||
|
|
||||||
|
size_t numberGlobal = 0;
|
||||||
// actual localization
|
// actual localization
|
||||||
for (const auto& file : _globalFiles) {
|
for (const auto& file : _globalFiles) {
|
||||||
auto pos = outFile.tellp();
|
auto pos = outFile.tellp();
|
||||||
for (const auto& kv : file.second.GetMap()) {
|
for (const auto& kv : file.second.GetMap()) {
|
||||||
outFile << kv.first << "|" << kv.second << std::endl;
|
outFile << kv.first << "|" << kv.second << std::endl;
|
||||||
|
numberGlobal++;
|
||||||
}
|
}
|
||||||
auto end = outFile.tellp();
|
auto end = outFile.tellp();
|
||||||
auto length = end - pos;
|
auto length = end - pos;
|
||||||
auto data = globalFilesPositions[file.first];
|
auto data = globalFilesPositions[file.first];
|
||||||
outFile.seekp(data);
|
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 << "~";
|
||||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << length;
|
outFile << std::setfill('0') << std::setw(4) << std::hex << length;
|
||||||
outFile.seekp(end);
|
outFile.seekp(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t numberTemp = 0;
|
||||||
for (const auto& file : _tempFiles) {
|
for (const auto& file : _tempFiles) {
|
||||||
auto pos = outFile.tellp();
|
auto pos = outFile.tellp();
|
||||||
for (const auto& kv : file.second.GetMap()) {
|
for (const auto& kv : file.second.GetMap()) {
|
||||||
outFile << kv.first << "|" << kv.second << std::endl;
|
outFile << kv.first << "|" << kv.second << std::endl;
|
||||||
|
numberTemp++;
|
||||||
}
|
}
|
||||||
auto end = outFile.tellp();
|
auto end = outFile.tellp();
|
||||||
auto length = end - pos;
|
auto length = end - pos;
|
||||||
auto data = tempFilesPositions[file.first];
|
auto data = tempFilesPositions[file.first];
|
||||||
outFile.seekp(data);
|
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 << "~";
|
||||||
outFile << std::setfill ('0') << std::setw(4) << std::hex << length;
|
outFile << std::setfill('0') << std::setw(4) << std::hex << length;
|
||||||
outFile.seekp(end);
|
outFile.seekp(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
outFile.close();
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
#include "LocalizationFile.hpp"
|
#include "LocalizationFile.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char PossibleSeparators[] = {
|
||||||
|
',', ';', '|', '\t', ':'
|
||||||
|
};
|
||||||
|
|
||||||
void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
||||||
if (!std::filesystem::exists(path)) {
|
if (!std::filesystem::exists(path)) {
|
||||||
@@ -21,9 +35,11 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
|||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
if (firstLine) {
|
if (firstLine) {
|
||||||
firstLine = false;
|
firstLine = false;
|
||||||
if (line.substr(0, 4) == "sep=") {
|
for (auto& s :PossibleSeparators) {
|
||||||
sep = line[4];
|
if (line.find(s) != std::string::npos){
|
||||||
continue;
|
sep = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string key;
|
std::string key;
|
||||||
@@ -33,6 +49,9 @@ void LocalizationFile::LoadFile(const std::filesystem::path& path) {
|
|||||||
std::getline(linestream, value, sep);
|
std::getline(linestream, value, sep);
|
||||||
if (key.empty())
|
if (key.empty())
|
||||||
continue;
|
continue;
|
||||||
|
if (!IsKeyValid(key)){
|
||||||
|
std::cout << "Key not valid: '" << key << "'. Skipping key." << std::endl;
|
||||||
|
}
|
||||||
_map[key] = value;
|
_map[key] = value;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user