From 37bd35cdfed87a10c4cd833c698256700469ff37 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Wed, 7 Jul 2021 17:45:40 +0200 Subject: [PATCH] Added special characters conversion on file import and export for online translations --- .../main/webapp/js/developer/translations.js | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/webapp/src/main/webapp/js/developer/translations.js b/webapp/src/main/webapp/js/developer/translations.js index 0964ae326..4897c531f 100644 --- a/webapp/src/main/webapp/js/developer/translations.js +++ b/webapp/src/main/webapp/js/developer/translations.js @@ -121,13 +121,13 @@ class PropInfo { if (followLine) { followLine = isNextLineFollow(lines[i]); var lineValue = lines[i].replace(/\\$/, ""); - overridenTranslations.set(lineKey, overridenTranslations.get(lineKey) + lineValue); + overridenTranslations.set(lineKey, overridenTranslations.get(lineKey) + unescapeHTML(lineValue)); } else { followLine = isNextLineFollow(lines[i]); lineKey = getLineKey(lines[i]); if (lineKey.trim() != "") { let lineValue = getLineValue(lines[i]); - overridenTranslations.set(lineKey, lineValue); + overridenTranslations.set(lineKey, unescapeHTML(lineValue)); } } } @@ -186,7 +186,7 @@ class PropInfo { var fileName = "export_" + date.toLocaleString() + "_all.properties"; var lines = []; for (let [key, value] of overridenTranslations) { - lines.push(key + " = " + value); + lines.push(key + " = " + escapeHTML(value)); } saveFile(fileName, lines); } @@ -266,7 +266,7 @@ class PropInfo { var value = input.nextSibling.value; } else { var value = input.value; - if (pageTranslations.get(key).rawText != value) { + if (pageTranslations.get(key).rawText != escapeHTML(value)) { input.style.backgroundColor = "#8BAB2E"; overridenTranslations.set(key, value); } else { @@ -438,6 +438,26 @@ class PropInfo { pageTranslations.set(key, propInfo); } } + function escapeHTML(input) { + return input + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'") + .replace(/‘/g, "‘") + .replace(/’/g, "’"); + } + function unescapeHTML(input) { + return input + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, "\"") + .replace(/'/g, "'") + .replace(/‘/g, "‘") + .replace(/’/g, "’"); + } window.addEventListener('load', function() { setTimeout(function() {