From ed6e943e5745067beea780efdb7e32fa5c088950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Sun, 10 Mar 2024 23:18:40 +0000 Subject: [PATCH] script correction --- genLang.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/genLang.js b/genLang.js index 37719d6f..8a4dc169 100644 --- a/genLang.js +++ b/genLang.js @@ -1,8 +1,8 @@ const fs = require('fs'); const translate = require('@iamtraction/google-translate'); -const configDir = "./config/_default"; -const contentDir = "./content"; +const configDir = "./exampleSite/config/_default"; +const contentDir = "./exampleSite/content"; const defaultLang = "en"; const targetLang = process.argv[2] || "en"; const targetLangIso = targetLang == "pt" ? "pt-pt" : targetLang; @@ -25,8 +25,11 @@ async function convert(text, from, to) { from: from, to: to }; - var translated_text = await translate(text, options); - return translated_text.text; + var translated_text = await translate(text, options) + .catch(err => { + console.error(err); + });; + return translated_text && translated_text.text? translated_text.text : ''; } async function processFrontMatter(block) { @@ -66,10 +69,10 @@ async function processFile(filePath) { var array = fileContent.split("---\n") var frontMatter = array[1]; var content = array[2]; - + var translatedFrontMatter = await processFrontMatter(frontMatter); var translatedContent = await convert(content, defaultLang, targetLang); - + var newFileContent = "---\n" + translatedFrontMatter + "---\n" + translatedContent; fs.writeFileSync(targetFilePath, newFileContent, 'utf8'); @@ -79,12 +82,12 @@ async function processFile(filePath) { async function processFolder(folderPath) { const files = fs.readdirSync(folderPath); + for (var i in files) { const file = files[i]; const filePath = `${folderPath}/${file}`; const isDir = fs.lstatSync(filePath).isDirectory(); console.log(filePath, isDir); - console.log(); if (isDir) { await processFolder(filePath); } else {