Fix loading PO files with missing newline after last msgstr

Fixes #20375.
This commit is contained in:
Rémi Verschelde 2018-07-24 13:32:37 +02:00
parent bfe52fc30a
commit 12d69ef53e

View file

@ -54,32 +54,25 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
int line = 1; int line = 1;
bool skip_this = false; bool skip_this = false;
bool skip_next = false; bool skip_next = false;
bool is_eof = false;
while (true) { while (!is_eof) {
String l = f->get_line(); String l = f->get_line().strip_edges();
is_eof = f->eof_reached();
if (f->eof_reached()) { // If we reached last line and it's not a content line, break, otherwise let processing that last loop
if (is_eof && l.empty()) {
if (status == STATUS_READING_STRING) { if (status == STATUS_READING_ID) {
memdelete(f);
if (msg_id != "") { ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
if (!skip_this) ERR_FAIL_V(RES());
translation->add_message(msg_id, msg_str); } else {
} else if (config == "")
config = msg_str;
break; break;
}
} else if (status == STATUS_NONE)
break;
memdelete(f);
ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
ERR_FAIL_V(RES());
} }
l = l.strip_edges();
if (l.begins_with("msgid")) { if (l.begins_with("msgid")) {
if (status == STATUS_READING_ID) { if (status == STATUS_READING_ID) {
@ -160,6 +153,15 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
f->close(); f->close();
memdelete(f); memdelete(f);
if (status == STATUS_READING_STRING) {
if (msg_id != "") {
if (!skip_this)
translation->add_message(msg_id, msg_str);
} else if (config == "")
config = msg_str;
}
if (config == "") { if (config == "") {
ERR_EXPLAIN("No config found in file: " + p_path); ERR_EXPLAIN("No config found in file: " + p_path);
ERR_FAIL_V(RES()); ERR_FAIL_V(RES());