Generalizing the three-way translation merge to any direction
In Three-way translation merge: keeping translated pages in sync with an LLM, we let an LLM merge changes made to one source page into the other languages. I called that a three-way translation merge. The base for each diff is a copy of the source page, kept per target language, as it was the last time that language was synced. I call that the simple system.
One source language works fine as long as everyone who edits can write it. Our company website had Swedish as its source for historical reasons. Today it has no source language, and runs the system in this post. (In the first post, and in the examples here, I use English as the source to make them easier to follow.) But we also had Norwegian native speakers in the company who wanted to write in Norwegian and have their changes reach the other languages. And even with English as the source, an editor who finds a factual error in the Swedish page has to go find the same sentence in the English page and change it there.
This post is about what changes when more than one language can be a source. It’s basically an LLM doing multi-master replication.
Since the LLM works on changes, the changes could be translated in any direction.
A language can be a source, whose edits are translated into the other languages, a target, which is synced from the sources, or both. In the first post, English was the only source. On our website, every language is both. I’ll call that the peer system, since every language is a peer. It complicates the bookkeeping, though.
Each target needs to know what it has seen of every source. So the bookkeeping has two rules:
- Every target keeps a copy of every other source language, as it was the last time the target was synced. These are the bases for its diffs.
- A language that is both a source and a target also keeps a copy of itself. The copy of itself tells the LLM what changed in that page since its last sync, so it doesn’t undo those changes.
With one source, that is one copy per target language, as in the first post. In the peer system, every language keeps a copy of every language: N² in total. The Swedish page has copies of the English page, the Norwegian page and itself, as they were the last time Swedish was synced.
You could also mix them. One could imagine having English, Swedish and Norwegian as source languages, and Spanish and Danish as pure target languages. My implementation only supports one source or all of them, and the rest of this post is about the peer system.
In files, each language’s folder inside .l10n now holds a copy of every language, including itself:
pages/ ├── sv/pricing.mdx the real pages ├── en/pricing.mdx └── no/pricing.mdx .l10n/ ├── sv/ what Swedish has seen │ ├── pages/sv/pricing.mdx │ ├── pages/en/pricing.mdx │ └── pages/no/pricing.mdx ├── en/ what English has seen │ ├── pages/sv/pricing.mdx │ ├── pages/en/pricing.mdx │ └── pages/no/pricing.mdx └── no/ what Norwegian has seen ├── pages/sv/pricing.mdx ├── pages/en/pricing.mdx └── pages/no/pricing.mdx
With peers, there are three operations:
- Edit: change a page, and the change should be translated into the other languages.
- Sync: bring a page up to date with the edits made in the other languages.
- Fix: change a page, and the change should stay in that language.
Edit
An edit only needs a commit. After you’ve edited and committed the English page, it no longer equals the other languages’ copies of it, so they are out of date, or stale.
Sync
A sync brings one page up to date with the other languages. It gets the diffs from every language that has changed. The sync for a target language has these steps:
- Gather the diffs between the target’s copies and the real pages, and the target page, into what I call a brief. The diff against its copy of itself is included too.
- Give the brief to the LLM, which edits the target page with its edit tool. As in the first post, it can also search and read the current pages of the other languages.
- Copy the real pages into the target language’s copies. The target language has now seen the changes in them.
The sync changed the target page, so the other languages would now see it as changed and be stale, even though the change is a translation of their own edits. So there is a fourth step:
- Merge what the sync changed in the target page into the other languages’ copies of it. This is a three-way merge1: the change just made to the target page is merged into each other language’s copy of the target page, so from their point of view they have seen it. It has to be a merge and not a plain copy of the file. Another language’s copy of the target page can be behind on some other change to that page, and it still needs to see that change.
Here is the sync, step by step. (The figure and the interactive version leave out each language’s copy of itself.)
Fix
In the simple system, you could edit a target page and be done. Only a change to the source page that shouldn’t be translated needed something extra: we patched each target language’s base with it. With peers, every page is a source, so every edit makes the others stale. If you add a sentence about card payments to the English page, the next sync translates it into Swedish and Norwegian too.
So every language needs what the source page had in the simple system: a way to say “this change should not be translated into the other languages”. I call this a fix. It works the same way as that patch, and it is the same operation as step 4 of the sync. We take what changed in the English page and merge it into the other languages’ copies of English, as if it had already been translated. Then they are not stale, and the change won’t be in their diff at the next sync. A fix can be a correction, like a better word for what the LLM wrote, or a localization, like the card-payment sentence.
A fix needs a “before” to diff against. In my implementation, each operation is one git commit, and a fix is what changed in the file since the last commit. So if you edit a page and then fix the same page before committing the edit, both count as the fix, and the edit is never translated into the other languages.
The fix is also merged into the fixing language’s copy of itself, so it is not in that language’s own diff either. My first version left it out of that copy, and tests showed that was a mistake.
Here an English rewording is merged into the others’ copies of English without being translated:
Since both a sync and a fix merge changes into copies, a copy can end up as a version of a page that was never committed, for example the old English page plus a fix. So with peers the base can’t be recorded as a commit hash. It has to be a copy.
Complexity
The peer system is more complicated than the simple system in these ways:
- N² copies instead of one per target language. With three languages, that’s nine copies of each page. They add almost nothing to the repository, as with a single source, but all nine files are in the working directory.
- The merge after every sync, which can conflict. When it does, the languages it came from get the translation in their next diff, and translate it back.
- The merge in a fix, which can also conflict. Then that copy is left alone, the fix shows up in that language’s next diff, and it may get translated after all.
- Fixes rely on commits. If an edit and a fix end up in the same commit, the edit is never translated.
- Contradicting edits. If English and Swedish change the same sentence in different ways, Norwegian gets both diffs and can’t know which one to follow. In my implementation the LLM has a tool for asking the person who started the sync, instead of guessing.
- Changes the LLM makes without being asked. The merge after a sync takes everything that changed in the target page, so an unrequested change works like a fix and is never translated into the other languages.
I test the peer system the same way as the simple system. It has 53 cases, and I ran each one three times with Claude Sonnet 5.5:
| The LLM gets | Runs passed |
|---|---|
| The diffs and the target page, and tools to search and read the other pages | 159 of 159 |
| The diffs and the target page | 156 of 159 |
| The diffs, the target page and the copies | 158 of 159 |
| Only the current pages, no diffs | 108 of 159 |
All the results are published, with the diffs and without.
Summary
- Since the LLM works on changes, a change can start in any language and be translated into the others.
- For that, every target keeps a copy of every source language as it was at the target’s last sync, and a language that is both also keeps a copy of itself.
- There are three operations. An edit is a change that should propagate to the other languages. A sync brings one page up to date with the others. A fix is a change that stays in its own language.
- After a sync or a fix, the change is merged into the other languages’ copies, so it isn’t translated again.
This is more bookkeeping than the simple system, and it has more ways to go wrong. I would only use it if people need to edit in their own language. On our website they do, which is why I built it. If only one language is edited, the simple system does the same job with one copy per target language.
The implementation is the same as in the first post: Obelum, which my CMS Plinto uses.
Have you seen someone do this, or something similar? Leave a comment below.
Footnotes
-
For step 4 of a sync, and for a fix, the three-way merge uses the page before the change as
base, the page after the change astheirs, and the other language’s copy of the page asours. ↩