Kaiyichen xp — Visual Designer

For the best experience
Enter Full Screen (F11)

Portfolio®︎

Kaiyichen XP

繁體中文 English 简体中文 한국어 日本語 ภาษาไทย

One Website in Six Languages: How I Use OpenAI to Translate WordPress

Kaiyi Chen ·

My site has Traditional Chinese, English, Simplified Chinese, Korean, Japanese, and Thai. I moved from replacing strings in one post to one post per language, while OpenAI translates only text and a Cloudflare Worker keeps the key away from WordPress.

My site has six languages. Traditional Chinese is the source, with English, Simplified Chinese, Korean, Japanese, and Thai alongside it. The hard part was not translating sentences; it was deciding where translations live, how their URLs work, and how to know which versions are outdated after the source changes.

I did not install a multilingual plugin. The URLs, SEO, and content model were already part of my theme, so I made multilingual content part of that same system.

The first version put every language in one post

The first approach stored the Chinese source in one post and replaced strings on the front end according to the current language. The admin screen stayed clean, but titles could remain in Chinese, every language shared one SEO setting, slugs could not be translated, and draft or outdated states had nowhere clear to live.

That approach assumes every language has the same structure and only different words. Titles, URLs, and search descriptions should not be derived blindly from the source, so every exception made the data harder to maintain.

One post for each language

I changed to a Polylang-like structure: each language is an independent WordPress post linked back to the Traditional Chinese source. Titles, excerpts, content, slugs, and SEO settings belong to each translation. Cover images, comments, likes, and view counts belong to the source and are shared.

Each translation can now have its own publication state and can be marked current, outdated, or manually edited. The admin list shows source posts by default instead of becoming six times longer.

URLs and SEO must be language-specific too

Traditional Chinese has no language prefix. Other languages use prefixes such as /en/ and /ja/, and each translation has its own slug. Canonical URLs, sitemaps, and social previews can therefore point to the right language.

Pages output hreflang links for each language and use Traditional Chinese as x-default. Categories and tags follow the same language model, falling back to the source only when a translation does not exist.

AI translates text, not the article structure

My posts use Gutenberg blocks with headings, lists, images, tables, and links. Sending the entire HTML to a model makes it tempting for the model to change block markup or classes.

I first extract translatable text: paragraphs, headings, list items, captions, table cells, and image alt text. The model receives a JSON array and must return the same number of items. I then put the translated text back into the original positions.

The count check matters more than a clever prompt. If the input and output lengths differ, the translation is rejected rather than saved with shifted paragraphs. Inline links and bold markup must also remain intact.

Keep the key out of WordPress

The production OpenAI key lives only in a Cloudflare Worker. WordPress calls the Worker with a separate token; the Worker forwards only required fields, limits request size, and compares the token in constant time. If the token leaks, it can be replaced without exposing the OpenAI key on the WordPress host.

Local development may use an environment variable, but production does not. A small model is enough because it receives short segments and strict formatting rules, not an entire document to reason about.

Do not overwrite manual edits automatically

Every translation records a fingerprint of the source content. If the source changes, the translation is marked for review while the old version remains visible. If someone polished a translation manually, batch translation refuses to overwrite it unless a force option is explicit.

That makes AI a rerunnable tool instead of a background process that silently changes posts. Interface labels stay in a separate dictionary; short fixed strings belong there, while evolving articles with their own URLs and SEO belong in independent posts.

AI Applications