HUGO Markdown File Translator

This workflow streamlines the translation of HUGO markdown files into target languages while preserving file structure and formatting. Leveraging AI language models, it ensures accurate translations of content, maintains TOML front matter integrity, and applies translation best practices for static site generators.

How the AI Flow works - HUGO Markdown File Translator

How the AI Flow works

Receive Markdown File and Translation Variables

Accepts user-uploaded HUGO markdown file and target language information as input.

Extract Destination Language

Parses input variables to determine the target language for translation using an AI model.

Retrieve Existing Translations

Searches for the best existing translations or related documentation to provide context for the translation.

Translate Markdown File with Structure Preservation

Uses AI to translate the markdown file into the target language, ensuring original formatting, TOML front matter, and markdown structure are preserved.

Output Translated File

Returns the translated markdown file, ready for use in HUGO projects.

Prompts used in this flow

Below is a complete list of all prompts used in this flow to achieve its functionality. Prompts are the instructions given to the AI model to generate responses or perform actions. They guide the AI in understanding user intent and generating relevant outputs.

Prompt

Prompt template for the translation of HUGO markdown files, including restrictions and example formatting.

                You are professional translator translating HUGO markdown file to destination language, which is defined in input variables:
{all_input_variables}

-- TRANSLATION RESTRICTIONS --
{context}
-- END RESTRICTIONS --

Input file is HUGO file with Front matter section formatted with toml language (translated file should start with toml, than contains variables in toml format ), than file continue with markdown text

Keep the same formatting and structure as original input file, make sure all control characters are used in the same form as in original input.
Don't translate text, which are part of HTML tags or field names in the front matter section - translate just field values.
In the translation properly handle quotes 
--

--EXAMPLE of file structure START:
title = "any title"

                                
any other markdown text ...

-- EXAMPLE END

--
RETURN JUST TRANSLATED FILE, NOTHING ELSE!
INPUT FILE TO TRANSLATE:
{input}
This is a final line added for robust parsing.

            

Components used in this flow

Below is a complete list of all components used in this flow to achieve its functionality. Components are the building blocks of every AI Flow. They allow you to create complex interactions and automate tasks by connecting various functionalities. Each component serves a specific purpose, such as handling user input, processing data, or integrating with external services.

Flow description

Purpose and benefits

Workflow Overview: Translations for HUGO Projects

This workflow is designed to automate the translation of markdown files used in HUGO projects, with special attention to preserving the file structure and formatting. The flow ensures that only the relevant text content is translated, while technical elements like front matter, markdown structure, and control characters remain intact. This is particularly useful for teams managing multi-language static sites built with HUGO, and looking to scale content localization while maintaining high quality and consistency.

Purpose and Utility

  • Automated Translation: The workflow leverages state-of-the-art language models (OpenAI GPT-4 variants) to provide high-quality translations for markdown files.
  • Structure Preservation: It carefully maintains the structure of HUGO markdown files, including front matter in TOML format, markdown headers, and special formatting.
  • Selective Translation: The flow is designed to avoid translating field names in front matter or text within HTML tags, focusing only on field values and markdown content.
  • Scalable Localization: By automating the translation process, this workflow enables rapid scaling to multiple languages with minimal manual effort.

Key Steps in the Workflow

The workflow consists of several interconnected components. Here’s a step-by-step outline:

StepComponentFunction
1Chat InputAccepts the markdown file to be translated and any required variables (e.g., target language).
2Prompt Template (input var)Extracts the destination language name from input variables for downstream use.
3LLM OpenAI (nano)Uses a lightweight GPT-4 model to process prompts.
4Generator (get language name)Generates the destination language name from the provided variables.
5Document Retriever (GetBestTranslation)Searches for existing best translations or context from internal/document sources.
6Prompt Template (Prompt)Crafts a detailed prompt instructing the LLM on how to translate, with restrictions and examples.
7LLM OpenAI (full)Uses a full-feature GPT-4 model (with large context) to perform the translation.
8GeneratorExecutes the translation using the above prompt and model.
9Chat OutputDisplays the translated markdown file in the output interface.

Workflow Logic in Detail

  • Input Handling: The user submits a markdown file and specifies the target language. The workflow extracts relevant variables for use in prompts.
  • Language Extraction: The first part of the workflow determines the name of the target language from the input, using a lightweight LLM and a custom prompt template.
  • Contextual Retrieval: It optionally retrieves existing translations or relevant documentation to provide additional context and ensure translation consistency.
  • Translation Prompt Construction: A comprehensive prompt is constructed, detailing formatting rules, translation restrictions, and file structure expectations. An example file structure is given to the model, with strict instructions on what to translate and what to preserve.
  • Translation Generation: The main translation is performed using a powerful LLM, ensuring high-quality output while strictly adhering to the formatting and structural requirements.
  • Output: The translated markdown file is presented for user review or further automated processing.

Why This Workflow is Useful

  • Consistency: Ensures that all translated files follow the strict formatting and structural guidelines required by HUGO projects.
  • Efficiency: Substantially reduces the manual effort involved in translating and formatting markdown files for static site generators.
  • Scalability: Enables easy scaling to multiple languages and large volumes of content.
  • Quality Control: By using both context-aware retrieval and explicit translation instructions, it minimizes errors typical of naive machine translation approaches.

Special Considerations

  • Field-Specific Rules: The workflow is careful to only translate field values in the front matter, not the field names or structural elements.
  • Formatting Integrity: Control characters like + + + and markdown/HTML elements are preserved as required by HUGO and TOML specifications.
  • Extensibility: The modular approach (with retrievers, prompt templates, and generators) allows for easy adaptation as requirements evolve.

In summary, this workflow provides an end-to-end, reliable, and scalable solution for translating HUGO markdown files, making it highly valuable for organizations managing multilingual static sites or documentation projects.

Let us build your own AI Team

We help companies like yours to develop smart chatbots, MCP Servers, AI tools or other types of AI automation to replace human in repetitive tasks in your organization.

Learn more