Automating WordPress Article Translation with n8n and Gemini

When operating a blog over a long period, the technical articles and development logs accumulated in the past become valuable information assets. However, if you continue publishing only in Japanese, the reachable readers are limited to domestic users, missing opportunities to acquire search traffic from overseas, particularly English-speaking regions.

Our blog, “Nando Kobo," also features over 180 articles, and we wanted to internationalize them to expand overseas. However, manually translating over 180 articles, copying and pasting them one by one from the WordPress dashboard, and publishing them would require an enormous amount of man-hours, making it completely unrealistic.

Therefore, we set out to build a fully automated pipeline by combining “n8n," a workflow automation tool running in a self-hosted environment, and a generative AI API, to automatically fetch and translate past articles and publish them as new entries in accordance with the specifications of the multilingual plugin “Bogo."

n8n flow

目次

Advertisement

Building a Fully Automated Translation Pipeline with n8n and Generative AI

In this system, translation queues are managed using n8n’s built-in “Data Tables" feature without setting up a dedicated external database.

The overall processing procedure of the system is as follows:

  • Queue Management: Holds the target article ID list and statuses (pending / completed) in Data Tables.
  • Source Article Retrieval: Retrieves the body, slug, featured image, category, and tags of unprocessed articles via the WordPress REST API.
  • AI Translation: Passes the title and body HTML to the Gemini API, translating them into English while preserving the HTML structure.
  • Data Integration: Formats the JSON response using an n8n Code node and maps the featured image and taxonomy information.
  • WordPress Posting: Newly registers the English article via the REST API and automatically links the Bogo language pair.
  • Status Update: Updates the target record in Data Tables to completed, preparing for the next scheduled execution.

By periodically executing this series of flows using a schedule trigger, we aimed to create a mechanism that translates past articles into English sequentially without requiring any manual intervention from the administrator.

 

Requirements to Leverage the 500 Free Tier and Ensure Data Integrity

When building the pipeline, we established the following quantitative and qualitative requirements:

  • Processing Speed and Cost: Fully process over 180 articles within a few days utilizing the free-tier API.
  • 0% Data Corruption Rate: Translate the HTML structure within the body, WordPress block comments (Gutenberg format), embedded iframes such as YouTube, and code blocks (SyntaxHighlighter format) without any corruption.
  • Complete Synchronization of Multilingual Information: Perfectly match the slug, categories, tags, and featured images of the English articles with the Japanese version, and ensure Bogo’s language switching links function properly.

Particularly in selecting the LLM model, “Gemini 3 Flash," which was initially considered, had its free-tier daily request limit (RPD) restricted to 20 requests, which calculated to requiring over 9 days to process all articles. Therefore, by adopting “Gemini 3.5 Flash Lite," which has an RPD set to 500, we established a foundation capable of processing all articles in 1 to 2 days without hitting API quota limits.

model list

Three Technical Barriers in Bogo Integration Faced During Automated API Posting

During the implementation process, we faced three major technical barriers originating from the specifications of the WordPress REST API and the Bogo plugin.

403 Error Upon Private Metadata Registration

Bogo manages multilingual information using post metadata (_locale, _original_post). However, meta keys starting with an underscore are treated as “protected custom fields" due to WordPress REST API security specifications, and even when using administrator-privileged application passwords, a 403 rest_cannot_update error was returned, rejecting the update.

The -2 Suffix Issue Caused by Slug Duplicate Detection

To switch languages in Bogo, the Japanese and English versions must maintain the exact same slug. However, when making a POST request via the REST API specifying the same slug as the original article, WordPress’s standard duplication check (wp_unique_post_slug) triggered first, forcibly appending -2 to the end of the slug.

Bogo’s Matching Conditions Revealed Through MariaDB Analysis

To investigate the issue where created English articles did not link with the Japanese version, we logged directly into MariaDB to check the actual data in the wp_postmeta table.

SELECT post_id, meta_key, meta_value
FROM wp_postmeta
WHERE post_id IN (58, 4712)
AND meta_key IN ('_locale', '_original_post');

As a result of the investigation, it turned out that in normal multilingual pairs created via the dashboard, not only on the English article side, but “its own URL (https://donguri3.net/?p=ID) is also saved as _original_post on the Japanese original article side as well." Bogo was specified to recognize them as a group only when the exact same _original_post URL exists on both articles.

Implementing Server-Side Hooks and Optimizing the Workflow

To resolve these technical barriers, we integrated WordPress server-side hook processing with n8n workflow design.

Bidirectional Meta Synchronization and Automatic Slug Correction via functions.php

We added code to bypass the REST API standard meta processing, executing bidirectional metadata writing and slug re-application within the article creation hook (rest_insert_post).

add_action( 'rest_insert_post', function( $post, $request, $creating ) {
$params = $request->get_json_params();

// 1. Save locale for the English article
if ( ! empty( $params['bogo_locale'] ) ) {
    update_post_meta( $post->ID, '_locale', sanitize_text_field( $params['bogo_locale'] ) );
}

// 2. Save the original article URL to both the "English article" and "Japanese original article"
if ( ! empty( $params['bogo_original_post'] ) ) {
    $orig_url = esc_url_raw( $params['bogo_original_post'] );
    
    // Save to the English article side
    update_post_meta( $post->ID, '_original_post', $orig_url );

    // Save its own URL to the Japanese original article side as well
    if ( preg_match( '/[?&]p=(\d+)/', $orig_url, $matches ) ) {
        $orig_post_id = (int)$matches[1];
        update_post_meta( $orig_post_id, '_original_post', $orig_url );
    }
}

// 3. Re-apply the slug (remove -2 and overwrite with the original slug)
if ( ! empty( $params['slug'] ) ) {
    remove_action( 'rest_insert_post', __FUNCTION__ );
    wp_update_post( array(
        'ID'        => $post->ID,
        'post_name' => sanitize_title( $params['slug'] ),
    ) );
}
}, 10, 3 );

Strict LLM Translation Prompts

To prevent tag corruption and code breakage, we organized and optimized the system prompt passed to the Gemini API.

 You are an expert technical translator for the engineering blog "Nando Kobo" (納戸工房). Translate the provided Japanese blog title and HTML content into natural, accurate, and professional English.
Strict Translation Rules:
1. HTML & Block Preservation:
  - Preserve all HTML structures, tags, Gutenberg block comments (), , , and elements exactly as they are.
  - DO NOT modify, translate, or delete any URLs inside "src", "href", or "data-*" attributes (especially YouTube embed URLs).
2. Code & Technical Terms:
  - DO NOT translate anything inside 
...</pre>
<p>blocks, &#8230; tags, command lines, file paths, or configuration keys.<br />
&#8211; Keep Japanese proper nouns or specific brand names accurate.<br />
3. Output Format:<br />
&#8211;</p>
<p>Output strictly a single valid JSON object containing exactly two keys: &#8220;title&#8221; and &#8220;content&#8221;.<br />

Robust Data Mapping via n8n Code Node

Safely parses the output text from the Gemini API, combines it with the original article's meta information (featured image ID, categories, tags), and generates data for the WordPress POST.

const rawResponse = $input.first().json;
let responseText = rawResponse.candidates[0].content.parts[0].text;

responseText = responseText.replace(/^(?:json)?\\s*/i, '').replace(/\\s*$/i, '').trim();

let parsedData;
try {\sparseData = JSON.parse(responseText);
} catch (e) {
// Sanitization process when raw line breaks are included
const sanitized = responseText.replace(/\\r?\
/g, '\
');\sparseData = JSON.parse(sanitized);
}

const origPost = $('HTTP Request: GET Post').first().json;

return [{
json: {
original_id: origPost.id,
slug: origPost.slug,
title: parsedData.title,
content: parsedData.content,
status: 'publish',
featured_media: origPost.featured_media || 0,
categories: origPost.categories || [],
tags: origPost.tags || [],
bogo_locale: 'en_US',
bogo_original_post: `https://donguri3.net/?p=${origPost.id}`
}
}];

Multilingual Linking Realized with Zero Operational Man-Hours and Future Access Verification

As a result of operating the constructed pipeline, everything from translation to automatic posting to WordPress is now completed in approximately 15 to 30 seconds per article.

  • Complete Bogo Synchronization: We confirmed that the slugs of the created English articles do not have -2 appended and match the Japanese version, and language switching buttons operate correctly in both directions on the public pages.
  • Content Reproducibility: Embedded YouTube video iframes, syntax highlighting blocks, featured images, and taxonomy information were translated into English without any loss.
  • Stable Operation: By leveraging the 500 RPD tier of Gemini 3.5 Flash Lite, multilingualization of all articles progresses automatically without error stoppages caused by rate limits.

select model

Regarding how actual overseas access numbers and search performance will transition as a result of batch-translating past articles this time, we plan to summarize the results again as an analytics report as soon as data for a certain period is gathered.

Conclusion

To translate over 180 past articles into English, we built an automated translation pipeline using n8n and Gemini 3.5 Flash Lite. We resolved REST API metadata 403 rejections, slug duplication, and Bogo's unique bidirectional meta-matching specifications by implementing server-side hooks based on MariaDB analysis. This established an operational framework capable of stably and automatically generating and publishing English-language articles linked with Japanese articles while fully protecting HTML and embedded structures.