translations: multi-line and special symbols support
This commit is contained in:
@@ -71,9 +71,26 @@ TSFile::Content TSFile::read(const PIString & path) {
|
||||
PIIOTextStream ts(&f);
|
||||
Context * cc = nullptr;
|
||||
Message msg;
|
||||
int phase = 0;
|
||||
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;
|
||||
}
|
||||
line.cutRight(14);
|
||||
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