Skip to content

Commit

Permalink
Merge pull request #1317 from nunocoracao/dev
Browse files Browse the repository at this point in the history
🔖 v2.61.1
  • Loading branch information
nunocoracao authored Mar 12, 2024
2 parents 6c6a559 + 35ab259 commit 65956f1
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 280 deletions.
366 changes: 96 additions & 270 deletions assets/css/compiled/main.css

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions genArticle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require('fs');
const translate = require('@iamtraction/google-translate');

const defaultLang = "en";
const targetLang = process.argv[2] || "en";
const filePath = process.argv[3];
const targetLangIso = targetLang == "pt" ? "pt-pt" : targetLang;
const targetFilePath = filePath.replace(".md", "." + targetLangIso + ".md");

async function convert(text, from, to) {
var options = {
from: from,
to: to
};
var translated_text = await translate(text, options);
return translated_text.text;
}

console.log(filePath);
console.log(targetFilePath);

async function processFrontMatter(block) {
var array = block.split("\n");
var translatedBlock = "";
for (var i = 0; i < array.length; i++) {
if (array[i].indexOf(":") > -1) {
var elements = array[i].split(":");
var newElement = "";
if (elements[0] == "title" ||
elements[0] == "description" ||
elements[0] == "summary" ||
elements[0] == "description" ||
elements[0] == "categories" ||
elements[0] == "tags") {
var translatedElement = elements[1] ? await convert(elements[1], defaultLang, targetLang) : elements[1];
newElement = elements[0] + ": " + translatedElement;
} else {
newElement = array[i];
}
} else {
newElement = array[i];
}
translatedBlock += newElement + "\n";
}
return translatedBlock;
}


async function main() {
const fileContent = fs.readFileSync(filePath, 'utf8');

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');
}

main();
104 changes: 104 additions & 0 deletions genLang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const fs = require('fs');
const translate = require('@iamtraction/google-translate');

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;


function createConfigs() {
const files = fs.readdirSync(configDir);
files.forEach(file => {
const filePath = `${configDir}/${file}`;
if (filePath.indexOf("languages.en.toml") > -1 ||
filePath.indexOf("menus.en.toml") > -1) {
var fileContent = fs.readFileSync(filePath, 'utf8');
fs.writeFileSync(filePath.replace(".en.toml", "." + targetLangIso + ".toml"), fileContent, 'utf8');
}
});
}

async function convert(text, from, to) {
var options = {
from: from,
to: to
};
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) {
var array = block.split("\n");
var translatedBlock = "";
for (var i = 0; i < array.length; i++) {
if (array[i].indexOf(":") > -1) {
var elements = array[i].split(":");
var newElement = "";
if (elements[0] == "title" ||
elements[0] == "description" ||
elements[0] == "summary" ||
elements[0] == "description" ||
elements[0] == "categories" ||
elements[0] == "tags") {
var translatedElement = elements[1] ? await convert(elements[1], defaultLang, targetLang) : elements[1];
newElement = elements[0] + ": " + translatedElement;
} else {
newElement = array[i];
}
} else {
newElement = array[i];
}
translatedBlock += newElement + "\n";
}
return translatedBlock;
}

async function processFile(filePath) {
console.log("translating", filePath)
if (filePath.indexOf("index.md") > -1) {

const targetFilePath = filePath.replace(".md", "." + targetLangIso + ".md");

const fileContent = fs.readFileSync(filePath, 'utf8');

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');

} else
return
}

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);
if (isDir) {
await processFolder(filePath);
} else {
await processFile(filePath);
}
}
}

async function createContent() {
processFolder(contentDir);
}

createConfigs();
createContent();
8 changes: 4 additions & 4 deletions i18n/id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ article:
likes:
one: "{{ .Count }} disukai"
other: "{{ .Count }} disukai"
part_of_series: "This article is part of a series."
part: "Part"
this_article: "This Article"
related_articles: "Related"
part_of_series: "Artikel ini merupakan bagian dari sebuah seri."
part: "Bagian"
this_article: "Artikel ini"
related_articles: "Terkait"

author:
byline_title: "Penulis"
Expand Down
35 changes: 33 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hugo-blowfish-theme",
"version": "2.61.0",
"version": "2.61.1",
"description": "Blowfish theme for Hugo",
"scripts": {
"postinstall": "vendor-copy",
Expand Down Expand Up @@ -110,6 +110,7 @@
"dependencies": {
"@headlessui/react": "^1.7.18",
"@heroicons/react": "^2.1.1",
"@iamtraction/google-translate": "^2.0.1",
"@tailwindcss/forms": "^0.5.7",
"commander": "^12.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion release-versions/hugo-latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.123.8
v0.123.8
3 changes: 1 addition & 2 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ module.exports = {
},
plugins: [
require("@tailwindcss/typography"),
require('@tailwindcss/forms'),
require("tw-elements/plugin.cjs"),
require('@tailwindcss/forms')
],
};

0 comments on commit 65956f1

Please sign in to comment.