From ae22cb6f20091e290cf6c30c049400535d6f1aca Mon Sep 17 00:00:00 2001 From: Dastgir Date: Sat, 8 Jun 2019 12:02:13 +0530 Subject: Fixed MultiLine support for translations --- src/map/script.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 967954fee..ec553fa76 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5349,6 +5349,7 @@ static int script_load_translation_file(const char *file, uint8 lang_id) char line[1024]; char msgctxt[NAME_LENGTH*2+1] = ""; struct script_string_buf msgid, msgstr; + struct script_string_buf *msg_ptr; int translations = 0; int lineno = 0; FILE *fp; @@ -5368,37 +5369,45 @@ static int script_load_translation_file(const char *file, uint8 lang_id) int i; lineno++; - if(len <= 1) + if (len <= 1) { + if (VECTOR_LENGTH(msgid) > 0 && VECTOR_LENGTH(msgstr) > 0) { + // Add string + if (script->load_translation_addstring(file, lang_id, msgctxt, &msgid, &msgstr)) + translations++; + + msgctxt[0] = '\0'; + VECTOR_TRUNCATE(msgid); + VECTOR_TRUNCATE(msgstr); + } continue; + } if (line[0] == '#') continue; - if (VECTOR_LENGTH(msgid) > 0 && VECTOR_LENGTH(msgstr) > 0) { + if (VECTOR_LENGTH(msgid) > 0) { + if (VECTOR_LENGTH(msgstr) > 0) { + msg_ptr = &msgstr; + } else { + msg_ptr = &msgid; + } if (line[0] == '"') { // Continuation line - (void)VECTOR_POP(msgstr); // Pop final '\0' - for (i = 8; i < len - 2; i++) { - VECTOR_ENSURE(msgstr, 1, 512); + (void)VECTOR_POP(*msg_ptr); // Pop final '\0' + for (i = 1; i < len - 2; i++) { + VECTOR_ENSURE(*msg_ptr, 1, 512); if (line[i] == '\\' && line[i+1] == '"') { - VECTOR_PUSH(msgstr, '"'); + VECTOR_PUSH(*msg_ptr, '"'); i++; } else { - VECTOR_PUSH(msgstr, line[i]); + VECTOR_PUSH(*msg_ptr, line[i]); } } - VECTOR_ENSURE(msgstr, 1, 512); - VECTOR_PUSH(msgstr, '\0'); + VECTOR_ENSURE(*msg_ptr, 1, 512); + VECTOR_PUSH(*msg_ptr, '\0'); continue; } - // Add string - if (script->load_translation_addstring(file, lang_id, msgctxt, &msgid, &msgstr)) - translations++; - - msgctxt[0] = '\0'; - VECTOR_TRUNCATE(msgid); - VECTOR_TRUNCATE(msgstr); } if (strncasecmp(line,"msgctxt \"", 9) == 0) { -- cgit v1.2.3-70-g09d2