mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-22 14:35:43 -06:00
script correction
This commit is contained in:
parent
a67798f18a
commit
ed6e943e57
1 changed files with 10 additions and 7 deletions
17
genLang.js
17
genLang.js
|
@ -1,8 +1,8 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const translate = require('@iamtraction/google-translate');
|
const translate = require('@iamtraction/google-translate');
|
||||||
|
|
||||||
const configDir = "./config/_default";
|
const configDir = "./exampleSite/config/_default";
|
||||||
const contentDir = "./content";
|
const contentDir = "./exampleSite/content";
|
||||||
const defaultLang = "en";
|
const defaultLang = "en";
|
||||||
const targetLang = process.argv[2] || "en";
|
const targetLang = process.argv[2] || "en";
|
||||||
const targetLangIso = targetLang == "pt" ? "pt-pt" : targetLang;
|
const targetLangIso = targetLang == "pt" ? "pt-pt" : targetLang;
|
||||||
|
@ -25,8 +25,11 @@ async function convert(text, from, to) {
|
||||||
from: from,
|
from: from,
|
||||||
to: to
|
to: to
|
||||||
};
|
};
|
||||||
var translated_text = await translate(text, options);
|
var translated_text = await translate(text, options)
|
||||||
return translated_text.text;
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});;
|
||||||
|
return translated_text && translated_text.text? translated_text.text : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processFrontMatter(block) {
|
async function processFrontMatter(block) {
|
||||||
|
@ -66,10 +69,10 @@ async function processFile(filePath) {
|
||||||
var array = fileContent.split("---\n")
|
var array = fileContent.split("---\n")
|
||||||
var frontMatter = array[1];
|
var frontMatter = array[1];
|
||||||
var content = array[2];
|
var content = array[2];
|
||||||
|
|
||||||
var translatedFrontMatter = await processFrontMatter(frontMatter);
|
var translatedFrontMatter = await processFrontMatter(frontMatter);
|
||||||
var translatedContent = await convert(content, defaultLang, targetLang);
|
var translatedContent = await convert(content, defaultLang, targetLang);
|
||||||
|
|
||||||
var newFileContent = "---\n" + translatedFrontMatter + "---\n" + translatedContent;
|
var newFileContent = "---\n" + translatedFrontMatter + "---\n" + translatedContent;
|
||||||
fs.writeFileSync(targetFilePath, newFileContent, 'utf8');
|
fs.writeFileSync(targetFilePath, newFileContent, 'utf8');
|
||||||
|
|
||||||
|
@ -79,12 +82,12 @@ async function processFile(filePath) {
|
||||||
|
|
||||||
async function processFolder(folderPath) {
|
async function processFolder(folderPath) {
|
||||||
const files = fs.readdirSync(folderPath);
|
const files = fs.readdirSync(folderPath);
|
||||||
|
|
||||||
for (var i in files) {
|
for (var i in files) {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
const filePath = `${folderPath}/${file}`;
|
const filePath = `${folderPath}/${file}`;
|
||||||
const isDir = fs.lstatSync(filePath).isDirectory();
|
const isDir = fs.lstatSync(filePath).isDirectory();
|
||||||
console.log(filePath, isDir);
|
console.log(filePath, isDir);
|
||||||
console.log();
|
|
||||||
if (isDir) {
|
if (isDir) {
|
||||||
await processFolder(filePath);
|
await processFolder(filePath);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue