Test
All checks were successful
Trigger build for deploying blog updates / build (push) Successful in 0s
All checks were successful
Trigger build for deploying blog updates / build (push) Successful in 0s
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.api_key
|
||||||
3
PREAMBLE.md
Normal file
3
PREAMBLE.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Translate markdown file
|
||||||
|
|
||||||
|
Do NOT add ```markdown enclosures just output the final markdown file.
|
||||||
27
content/blog/ca/automated_translation.md
Normal file
27
content/blog/ca/automated_translation.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
title: Traducció Automàtica
|
||||||
|
description: Problemes resolt!
|
||||||
|
date: 2026-06-10
|
||||||
|
slug: automated-translation
|
||||||
|
---
|
||||||
|
|
||||||
|
Hola!
|
||||||
|
|
||||||
|
He aconseguit fer una cosa molt divertida!
|
||||||
|
|
||||||
|
Un script que tradueix de forma automàtica els blogs als tres idiomes utilitzant intel·ligència artificial.
|
||||||
|
|
||||||
|
Ja, es una mica rotllo no fer-ho a mà, pero així no fa pal i puc escriure més blogs més ràpidament. Òbviament em llegeixo
|
||||||
|
les traduccions que surten de la màquina pero realment això agilitza tot un munt.
|
||||||
|
|
||||||
|
A part, he separat també ja de pas el repositori dels blogs amb el frontend. Abans estava tot dins d'una carpeta del repo
|
||||||
|
de [aranroog.com](https://git.aranroog.com/Syndria98/aranroog.com), pero ara les entrades al blog es troben dins d'aquest
|
||||||
|
[altre](https://git.aranroog.com/Syndria98/blogs).
|
||||||
|
|
||||||
|
Aquesta es la primera entrada que s'ha traduït automàticament. Si la veus en castellà o en anglès que sàpigues que has
|
||||||
|
estat llegint el text escrit per una intel·ligència artificial.
|
||||||
|
|
||||||
|
El model també que estic utilitzant no té censura ninguna, així que realment puc estar una mica tranquil sobre que posi
|
||||||
|
el que posi no es negarà a traduir-ho. Tampoc espero que prengui consciencia pròpia al traduir pel que escric.
|
||||||
|
|
||||||
|
En fi.
|
||||||
27
content/blog/en/automated_translation.md
Normal file
27
content/blog/en/automated_translation.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
title: Automated Translation
|
||||||
|
description: Problem solved!
|
||||||
|
date: 2026-06-10
|
||||||
|
slug: automated-translation
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello!
|
||||||
|
|
||||||
|
I've managed to do something really fun!
|
||||||
|
|
||||||
|
A script that automatically translates the blogs into three languages using artificial intelligence.
|
||||||
|
|
||||||
|
Yeah, it's a bit of a hassle not to do it by hand, but this way it doesn't take much effort and I can write more blogs faster. Obviously, I read through
|
||||||
|
the translations that come out of the machine, but it really speeds everything up a lot.
|
||||||
|
|
||||||
|
Also, I've gone ahead and separated the blogs repository from the frontend. Before, everything was inside a folder in the repo
|
||||||
|
of [aranroog.com](https://git.aranroog.com/Syndria98/aranroog.com), but now the blog posts are located in this
|
||||||
|
[other one](https://git.aranroog.com/Syndria98/blogs).
|
||||||
|
|
||||||
|
This is the first post that has been automatically translated. If you see it in Spanish or English, know that you've been
|
||||||
|
reading text written by an artificial intelligence.
|
||||||
|
|
||||||
|
The model I'm using is also completely uncensored, so I can really be a bit at ease knowing that no matter what it puts
|
||||||
|
out, it won't refuse to translate it. I also don't expect it to develop self-awareness while translating what I write.
|
||||||
|
|
||||||
|
Anyway.
|
||||||
26
content/blog/es/automated_translation.md
Normal file
26
content/blog/es/automated_translation.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
title: Traducción Automática
|
||||||
|
description: ¡Problemas resueltos!
|
||||||
|
date: 2026-06-10
|
||||||
|
slug: automated-translation
|
||||||
|
---
|
||||||
|
|
||||||
|
¡Hola!
|
||||||
|
|
||||||
|
¡He conseguido hacer algo muy divertido!
|
||||||
|
|
||||||
|
Un script que traduce automáticamente los blogs a los tres idiomas utilizando inteligencia artificial.
|
||||||
|
|
||||||
|
Sí, es un poco rollo no hacerlo a mano, pero así no me cansa y puedo escribir más blogs más rápido. Obviamente me leo
|
||||||
|
las traducciones que salen de la máquina, pero realmente esto agiliza todo un montón.
|
||||||
|
|
||||||
|
Además, he separado también de paso el repositorio de los blogs del frontend. Antes estaba todo dentro de una carpeta del repo
|
||||||
|
de [aranroog.com](https://git.aranroog.com/Syndria98/aranroog.com), pero ahora las entradas al blog se encuentran dentro de este
|
||||||
|
[otro](https://git.aranroog.com/Syndria98/blogs).
|
||||||
|
|
||||||
|
Esta es la primera entrada que se ha traducido automáticamente. Si la ves en castellano o en inglés, ten por seguro que has
|
||||||
|
estado leyendo un texto escrito por una inteligencia artificial.
|
||||||
|
|
||||||
|
El modelo que estoy utilizando tampoco tiene ninguna censura, así que realmente puedo estar tranquilo porque, ponga lo que ponga, no se negará a traducirlo. Tampoco espero que tome conciencia propia al traducir lo que escribo.
|
||||||
|
|
||||||
|
En fin.
|
||||||
27
original/blog/automated_translation.md
Normal file
27
original/blog/automated_translation.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
title: Traducció Automàtica
|
||||||
|
description: Problemes resolt!
|
||||||
|
date: 2026-06-10
|
||||||
|
slug: automated-translation
|
||||||
|
---
|
||||||
|
|
||||||
|
Hola!
|
||||||
|
|
||||||
|
He aconseguit fer una cosa molt divertida!
|
||||||
|
|
||||||
|
Un script que tradueix de forma automàtica els blogs als tres idiomes utilitzant intel·ligència artificial.
|
||||||
|
|
||||||
|
Ja, es una mica rotllo no fer-ho a mà, pero així no fa pal i puc escriure més blogs més ràpidament. Òbviament em llegeixo
|
||||||
|
les traduccions que surten de la màquina pero realment això agilitza tot un munt.
|
||||||
|
|
||||||
|
A part, he separat també ja de pas el repositori dels blogs amb el frontend. Abans estava tot dins d'una carpeta del repo
|
||||||
|
de [aranroig.com](https://git.aranroig.com/Syndria98/aranroig.com), pero ara les entrades al blog es troben dins d'aquest
|
||||||
|
[altre](https://git.aranroig.com/Syndria98/blogs).
|
||||||
|
|
||||||
|
Aquesta es la primera entrada que s'ha traduït automàticament. Si la veus en castellà o en anglès que sàpigues que has
|
||||||
|
estat llegint el text escrit per una intel·ligència artificial.
|
||||||
|
|
||||||
|
El model també que estic utilitzant no té censura ninguna, així que realment puc estar una mica tranquil sobre que posi
|
||||||
|
el que posi no es negarà a traduir-ho. Tampoc espero que prengui consciencia pròpia al traduir pel que escric.
|
||||||
|
|
||||||
|
En fi.
|
||||||
104
translate.py
Normal file
104
translate.py
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
LLAMA_URL = "https://ollama.epsem.aranroig.com/v1/chat/completions" # adjust if needed
|
||||||
|
|
||||||
|
|
||||||
|
def load_api_key(path=".api_key"):
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
return f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
|
def translate_text(text, system_prompt, api_key, model="llama"):
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {api_key}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"model": model,
|
||||||
|
"messages": [
|
||||||
|
{"role": "system", "content": system_prompt},
|
||||||
|
{"role": "user", "content": text}
|
||||||
|
],
|
||||||
|
"temperature": 0.2
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(LLAMA_URL, json=payload, headers=headers)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
return response.json()["choices"][0]["message"]["content"]
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_dir(path):
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
def load_preamble(path="PREAMBLE.md"):
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def build_output_path(input_file, lang):
|
||||||
|
"""
|
||||||
|
Converts:
|
||||||
|
original/blog/test.md
|
||||||
|
into:
|
||||||
|
content/blog/ca/test.md
|
||||||
|
"""
|
||||||
|
input_path = os.path.normpath(input_file)
|
||||||
|
parts = input_path.split(os.sep)
|
||||||
|
|
||||||
|
# Replace root folder "original" -> "content"
|
||||||
|
if parts[0] == "original":
|
||||||
|
parts[0] = "content"
|
||||||
|
|
||||||
|
filename = parts[-1]
|
||||||
|
name_no_ext = os.path.splitext(filename)[0]
|
||||||
|
|
||||||
|
base_path = parts[:-1] # everything except filename
|
||||||
|
|
||||||
|
output_dir = os.path.join(*base_path, lang)
|
||||||
|
return os.path.join(output_dir, f"{name_no_ext}.md")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("file", help="Path to markdown file")
|
||||||
|
parser.add_argument("--targets", nargs="+", required=True,
|
||||||
|
help="Target languages, e.g. ca es fr en")
|
||||||
|
parser.add_argument("--output_dir", default=".",
|
||||||
|
help="Base output directory (currently unused in path logic)")
|
||||||
|
parser.add_argument("--preamble_file", default="PREAMBLE.md",
|
||||||
|
help="Path to preamble markdown file")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
api_key = load_api_key()
|
||||||
|
system_prompt = load_preamble(args.preamble_file)
|
||||||
|
|
||||||
|
with open(args.file, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
for lang in args.targets:
|
||||||
|
print(f"Translating to {lang}")
|
||||||
|
full_prompt = (
|
||||||
|
f"{system_prompt}\n\n"
|
||||||
|
f"Translate into {lang}. Preserve markdown formatting."
|
||||||
|
)
|
||||||
|
|
||||||
|
translated = translate_text(content, full_prompt, api_key)
|
||||||
|
|
||||||
|
output_path = build_output_path(args.file, lang)
|
||||||
|
ensure_dir(os.path.dirname(output_path))
|
||||||
|
|
||||||
|
with open(output_path, "w", encoding="utf-8") as f:
|
||||||
|
f.write(translated)
|
||||||
|
|
||||||
|
print(f"Written: {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
Reference in New Issue
Block a user