Fix Translation Errors (Ren'Py Games and Translator++)

ferdi3113

Newbie
May 12, 2020
19
3
I use the Translator++ program. I wrote a code to simply solve problems that you may frequently encounter in other translation programs. This fixed bugs in all Ren'Py games I've translated so far.

Most of the problems arise from translating lines that should not be translated.
That's why I developed a method to extract those lines.

First things needed are:
You need to create 3 folders.
1.Folder contains the translated files of the game.
2.Folder Original file of the game
3.Folder this output folder must be empty.
These 3 folders and the "index.js" file I will leave below should be in the same folder.
Then, simply type the "node index.js" command in the folder using PowerShell or Console.
I explained it with pictures below:

TranslatorFix.png

Things you should pay attention to:
Check inside the files and only translate files with dialogue.
I only tried it in Ren'Py games and files with .rpy extension.
The translation program does not matter (I used Translator++), but check if the structure of the game is broken after the translation.
This process does not make a translation, it just corrects the faulty lines in the translation and may not always work.

After performing the process, replace the files in Folder 3 with those in the game folder and hopefully it will work.

Code:
const fs = require("fs");
const path = require("path");

// Klasör yollarını tanımla
const klasor1 = "Folder 1";
const klasor2 = "Folder 2";
const hedefKlasor = "Folder 3";

// Klasör 1'deki dosyaları listele
const dosyalar1 = fs.readdirSync(klasor1);

// Her bir dosya için işlem yap
dosyalar1.forEach((dosyaAdi) => {
  // Dosya yollarını oluştur
  const dosyaYolu1 = path.join(klasor1, dosyaAdi);
  const dosyaYolu2 = path.join(klasor2, dosyaAdi);
  const dosyaYolu3 = path.join(hedefKlasor, dosyaAdi);

  // Eğer Klasör 2'deki dosya varsa işleme devam et
  if (fs.existsSync(dosyaYolu2) && fs.statSync(dosyaYolu2).isFile()) {
    // Dosyaların içeriğini oku
    const icerik1 = fs.readFileSync(dosyaYolu1, "utf-8");
    const icerik2 = fs.readFileSync(dosyaYolu2, "utf-8");

    // Dosyaların içeriğini satır satır işle
    const yeniIcerik = icerik1.split("\n").map((line1, index) => {
      const line2 = icerik2.split("\n")[index];

      // Eğer satır .mp3, .png, .mp4 içeriyorsa, Klasör 2'den al
      if (line1.match(/\.(mp3|png|mp4|ogg|webm|webp|wav|avi|jpg|jpeg)/)) {
        return line2.match(/\.(mp3|png|mp4|ogg|webm|webp|wav|avi|jpg|jpeg)/) ? line2 : line1;
      }
      // Eğer satır [ ] içeriyorsa, Klasör 2'den al
      else if (line1.includes("[") && line1.includes("]")) {
        // Her bir [ ] ifadesini sırayla karşılaştır ve değiştir
        const parantezIcerik1Array = line1.match(/\[([^\]]+)\]/g);
        const parantezIcerik2Array = line2.match(/\[([^\]]+)\]/g);
        if (parantezIcerik1Array && parantezIcerik2Array) {
          let yeniLine = line1;
          for (let i = 0; i < parantezIcerik2Array.length; i++) {
            parantezIcerik2Array[i] = parantezIcerik2Array[i].match(/\[([^\]]+)\]/)[1];
          }
          parantezIcerik1Array.forEach((parantez, parantezIndex) => {
            yeniLine = yeniLine.replace(parantez, `[${parantezIcerik2Array[parantezIndex]}]`);
          });
          return yeniLine;
        }
      }

      // Diğer durumlarda aynı satırı kullan
      return line1;
    });

    // Yeni içeriği dosyaya yaz
    fs.writeFileSync(dosyaYolu3, yeniIcerik.join("\n"), "utf-8");
  }
});

console.log("Completed");
 
Last edited: