0

In order to translate some values inside a big JSON (from Italian to Russian) and split it in smaller files, I've created an offline html + Javascript page, in order to to obtain a series of JSON files in a zip (using JSZip). But the Cyrillic strings are not displayed correctly.

The page starts from a JSON stored in a variable, iterates it in order to find certain keys, then reassign the related values with others values taken from an associative array like this:

var translations = {};
translations['Retro Armadio'] = 'Задняя сторона шкафа';
translations['Stagno'] = 'Водонепроницаемый';
translations['Zoccolo'] = 'Цоколь';

The page then stringify the JSON in order to display it in a "pre" Tag and generates the zip file with the splitted JSONs using JSZip:

var zip = new JSZip();
for (const key in bigJSON){
  var currentJSON = JSON.stringify(bigJSON[key]);
  var currentFileName = key + "-ru.json";
  zip.file(currentFileName, currentJSON);
}

Unfortunately both inside the "pre" tag and inside the zip file, the Cyrillic strings are corrupted. I also tried using encodeURIComponent/decodeURIComponent, but I obtain strings like this: "Ð›Ð¸Ñ†ÐµÐ²Ð°Ñ Ñторона шкафа"

To edit the HTML page I'm using Notepad++ in UTF-8. I copy and paste the Cyrillic strings from MS Excel.

Axel
  • 1
  • 3
  • You must have a character encoding problem _somewhere_, because putting the JSON in a `pre` element works fine here, https://jsfiddle.net/voq7y361/ – CBroe Sep 30 '21 at 07:04
  • You may have saved your files in UTF-8 in npp - but what character encoding is the browser _interpreting_ them in? – CBroe Sep 30 '21 at 07:05
  • You have this in all pages, right? `` – mplungjan Sep 30 '21 at 07:05
  • 1
    @mplungjan thanks for the hint, I was using copied and pasted from an online example. Using instead, the page works properly. Thanks a lot! – Axel Sep 30 '21 at 07:15

0 Answers0