Archiv der Kategorie: n8n

n8n and Ollama translate Swedish

Due to some peculiar reason, I had to analyze the source code of an Infocom Z-machine story file. All the strings within the file were in Swedish, which I (sadly?) don’t understand.

Therefore, translating the strings into English seemed like the most logical approach. However, initial attempts using Google Translate or DeepL were unsuccessful. While the strings were typically translated reasonably well, the subsequent program code became severely corrupted.

The following approach provided the solution:

1. Using a PHP script, I read the source code file, extracted the strings using regular expressions, and saved them in a JSON file.

2. For translation, I downloaded the „translategemma“ model, which now runs on my on-premise AI machine (AMD Ryzen™ AI Max+ 395), along with Ollama and LM Studio.

3. I created an n8n workflow that can be triggered via a webhook. The workflow calls Ollama, which then uses translategemma for translation.

n8n workflow

n8n workflow calling Ollama via an AI Agent, triggered by a Webhook.

n8n AI Agent configuration

Configuration of the n8n AI Agent, e.g. the system prompt.

4. Another script reads the JSON file from step 1, sends each string to the n8n workflow for translation, and returns the English translation.

As a result, the Swedish strings in the source code are now automatically replaced with their English counterparts … everything is readable now … and … that’s all 😉

example translation

Example of a translation in the temporary JSON file.

Conclusio: This is a fast & neat solution, built using open-source and other license-free components. This solution can, of course, also be used for other languages. Furthermore, it could also be used to automatically translate comments in source code.