translations: multi-line and special symbols support
This commit is contained in:
@@ -19,13 +19,14 @@
|
||||
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pidir.h"
|
||||
#include "piliterals_string.h"
|
||||
#include "piprocess.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "pitime_win.h"
|
||||
#include "pitranslator.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef WINDOWS
|
||||
# include <psapi.h>
|
||||
# include <tlhelp32.h>
|
||||
@@ -114,7 +115,7 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
|
||||
# else
|
||||
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
|
||||
if (PRIVATE->hProc == 0) {
|
||||
piCoutObj << "Can`t open process with ID = " << pID_ << "," << errorString();
|
||||
piCoutObj << "Can`t open process with ID = "_tr << pID_ << "," << errorString();
|
||||
return false;
|
||||
}
|
||||
PRIVATE->tm.reset();
|
||||
|
||||
10
main.cpp
10
main.cpp
@@ -23,14 +23,10 @@ int main(int argc, char * argv[]) {
|
||||
// piCout << PIString::readableSize(50_KiB);
|
||||
// piCout << PIString::readableSize(1_GB);
|
||||
PITranslator::loadLang("ru");
|
||||
PITranslator::loadConfig("[C]\ntest string=\n"_u8);
|
||||
piCout << "test string1";
|
||||
piCout << "test string2"_tr;
|
||||
piCout << piTr("test string", "C1");
|
||||
PITranslator::loadConfig("[]\ntest \\\nstring=привет\n"_u8);
|
||||
piCout << "test\nstring"_tr;
|
||||
PITranslator::clear();
|
||||
piCout << "test string3";
|
||||
piCout << "test string4"_tr;
|
||||
piCout << piTr("test string", "C2");
|
||||
piCout << "test\nstring"_tr;
|
||||
// PICodeParser parser;
|
||||
// parser.parseFile("cmg_test.h");
|
||||
/*for (auto m: parser.macros) {
|
||||
|
||||
@@ -72,8 +72,25 @@ TSFile::Content TSFile::read(const PIString & path) {
|
||||
Context * cc = nullptr;
|
||||
Message msg;
|
||||
int phase = 0;
|
||||
bool multi_source = false, multi_translation = false;
|
||||
while (!ts.isEnd()) {
|
||||
auto line = ts.readLine().trim();
|
||||
if (multi_source) {
|
||||
if (line.endsWith("</source>")) {
|
||||
line.cutRight(9);
|
||||
multi_source = false;
|
||||
}
|
||||
msg.source += "\n" + unmask(line);
|
||||
continue;
|
||||
}
|
||||
if (multi_translation) {
|
||||
if (line.endsWith("</translation>")) {
|
||||
line.cutRight(14);
|
||||
multi_translation = false;
|
||||
}
|
||||
msg.translation += "\n" + unmask(line);
|
||||
continue;
|
||||
}
|
||||
switch (phase) {
|
||||
case 0:
|
||||
if (line == "<context>") phase = 1;
|
||||
@@ -97,7 +114,11 @@ TSFile::Content TSFile::read(const PIString & path) {
|
||||
if (cc) cc->messages[msg.source] = msg;
|
||||
phase = 2;
|
||||
} else if (line.startsWith("<source>")) {
|
||||
line.cutLeft(8).cutRight(9);
|
||||
line.cutLeft(8);
|
||||
if (line.endsWith("</source>"))
|
||||
line.cutRight(9);
|
||||
else
|
||||
multi_source = true;
|
||||
msg.source = unmask(line);
|
||||
} else if (line.startsWith("<location")) {
|
||||
PIString trs = line.takeRange('<', '>').cutLeft(8);
|
||||
@@ -117,7 +138,10 @@ TSFile::Content TSFile::read(const PIString & path) {
|
||||
PIString v = trs.takeRange('\"', '\"');
|
||||
if (t == "type") msg.type = v;
|
||||
}
|
||||
if (line.endsWith("</translation>"))
|
||||
line.cutRight(14);
|
||||
else
|
||||
multi_translation = true;
|
||||
msg.translation = unmask(line);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -68,6 +68,11 @@ void help() {
|
||||
}
|
||||
|
||||
|
||||
PIString fromCode(const PIString & in) {
|
||||
return in.replacedAll("\\n", '\n').replaceAll("\\r", '\r').replaceAll("\\t", '\t');
|
||||
}
|
||||
|
||||
|
||||
void gatherStrings(TSFile::Content & content, const PIString & file, const PIString & file_loc) {
|
||||
PIString source, context;
|
||||
int pos = -1, ppos = 0, line = -1;
|
||||
@@ -129,14 +134,13 @@ void gatherStrings(TSFile::Content & content, const PIString & file, const PIStr
|
||||
}
|
||||
}
|
||||
|
||||
content[context].confirm(source, file_loc, line);
|
||||
content[context].confirm(fromCode(source), file_loc, line);
|
||||
pos = ppos;
|
||||
piCout << "Context = \"" << context << "\", message = \"" << source << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
auto & ec(content[""]);
|
||||
content[context].confirm(source, file_loc, line);
|
||||
pos = -1;
|
||||
for (;;) {
|
||||
source.clear();
|
||||
@@ -156,7 +160,7 @@ void gatherStrings(TSFile::Content & content, const PIString & file, const PIStr
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ec.confirm(source, file_loc, file.lineNumber(pos));
|
||||
ec.confirm(fromCode(source), file_loc, file.lineNumber(pos));
|
||||
piCout << "_tr = \"" << source << "\"";
|
||||
}
|
||||
}
|
||||
@@ -186,7 +190,7 @@ int main(int argc, char * argv[]) {
|
||||
PIString out_path = cli.argumentValue("output");
|
||||
|
||||
PIStringList files;
|
||||
const static PIStringList ext({"*.h", "*.hpp", "*.cpp", "*.cxx"});
|
||||
const static PIStringList ext({"h", "hpp", "cpp", "cxx"});
|
||||
for (const PIString & a: cli.optionalArguments()) {
|
||||
if (PIDir::isExists(a)) {
|
||||
auto dl = PIDir(a).allEntries();
|
||||
|
||||
Reference in New Issue
Block a user