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;
|
||||
|
||||
Reference in New Issue
Block a user