When every string has a key, alignment stops being a guessing game. You match keys, not positions.
A client sends version 2 of their app strings, a JSON file with a few thousand entries. You have version 1 and its Spanish translation, but nobody ever ran it through a CAT tool, so there is no translation memory. The order of the keys has changed, some strings are new and some were rewritten. Classic alignment, which pairs sentences by position and length, would make a mess of it.
You do not need it. Resource files (JSON, YAML, RESX, Android XML, .properties) carry something ordinary documents do not: a unique identifier for every string. If the same key exists in English and in Spanish, those two values are a translation pair, whatever order they are in. That is ID-based alignment.

Why it works so well
- No ambiguity. A key matches exactly one key. No length heuristics, no dictionary guesses.
- Order does not matter. Developers reorder, regroup and reformat files all the time. Keys survive all of it.
- Updates become cheap. Align the old source with the old target and you can pre-translate everything in the new version that did not change.
That last point needs one precaution, and most guides skip it.
Only reuse what did not change
A key that exists in both versions is not automatically safe to reuse. If the English text of app.delete changed from “Delete invoice” to “Delete this invoice”, the old Spanish translation now belongs to a different sentence. Reuse a translation only when the key and its source text are both unchanged, and send everything else to translation:
import json
from lxml import etree
XML_LANG = "{http://www.w3.org/XML/1998/namespace}lang"
def flatten(data, prefix=""):
for key, value in data.items():
if isinstance(value, dict):
yield from flatten(value, f"{prefix}{key}.")
else:
yield f"{prefix}{key}", value
def load(path):
with open(path, encoding="utf-8") as f:
return dict(flatten(json.load(f)))
def align_by_id(old_src, old_tgt, new_src, tmx_path, src_lang="en-US", tgt_lang="es-ES"):
"""Reuses the translation of every key whose source text did not change."""
old_src, old_tgt, new_src = load(old_src), load(old_tgt), load(new_src)
root = etree.Element("tmx", version="1.4")
etree.SubElement(root, "header", {
"creationtool": "align_by_id", "creationtoolversion": "1.0", "segtype": "paragraph",
"o-tmf": "json", "adminlang": "en", "srclang": src_lang, "datatype": "plaintext",
})
body = etree.SubElement(root, "body")
reused = []
for key, text in new_src.items():
if old_src.get(key) == text and key in old_tgt:
tu = etree.SubElement(body, "tu", tuid=key)
for lang, value in ((src_lang, text), (tgt_lang, old_tgt[key])):
tuv = etree.SubElement(tu, "tuv", {XML_LANG: lang})
etree.SubElement(tuv, "seg").text = value
reused.append(key)
etree.ElementTree(root).write(tmx_path, encoding="UTF-8", xml_declaration=True, pretty_print=True)
return reused, sorted(set(new_src) - set(reused))On a real update, with app.delete rewritten and a new app.export key in version 2:
>>> reused, to_translate = align_by_id("en_v1.json", "es_v1.json", "en_v2.json", "reuse.tmx")
>>> reused
['app.title', 'app.save', 'help']
>>> to_translate
['app.delete', 'app.export']The rest comes straight from the memory, and every translation unit keeps its key in the tuid attribute, so you can always trace it back to the file. Added, changed, unchanged and removed strings are different states, and each one deserves different treatment: I explain why in When a localization file becomes a build artifact.
The same without code: Okapi Rainbow
Rainbow, from the Okapi Framework, has an ID-based aligner built in.
- Look at the files first. Here the JSON values contain inline tags and XML entities, so the parser must treat them as code, not as text:

- Create a JSON filter configuration that marks those tags and entities as inline codes:

- Load the English file in Input 1 and the Spanish file in Input 2, both with that filter:

- Set the languages and the encoding (en-US to es-ES, UTF-8) in the Languages and Encodings tab:

- Build a pipeline with Utilities > Edit / Execute Pipeline… (Ctrl+P). It needs two steps: Raw Document to Filter Events, which parses the files, and ID-Based Aligner, which pairs them by key. Tick Generate a TMX file to save the alignment as a memory, and Copy to/over target if you also want the target file filled in. Then click Execute.


The result is a TMX in which every translation unit carries the JSON key in its tuid attribute (translation unit ID):

Rainbow aligns every key the two files share, so align version 1 with its translation and let your CAT tool do the rest when you translate version 2: unchanged strings come back as exact matches, and rewritten ones as fuzzy matches for a translator to review.
Paragraphs or sentences?
Each value becomes one translation unit, so long values give you paragraph-sized units. That is expected, because the key is the only reliable boundary. If you need sentence-level units, resegment the memory afterwards, as I explain in how to resegment a TMX by sentence.

The short version
- If strings have keys, align by key, not by position.
- Reuse a translation only when both the key and its source text are unchanged.
- Rainbow’s ID-Based Aligner does it without code; a short script does it inside any pipeline.
- Keep the key in the TMX (
tuid) so every unit can be traced back to its file.
For documents without identifiers, classic text alignment is still the way.