Skip to content

Optional analytics, session recording and advertising stay off unless you accept. You can reject them and use Transglot. Change your choice anytime in Cookie preferences. Cookie Policy

Back to the blog
Developer platform

How to Translate JSON i18n Files with AI

Three ways to translate a JSON locale file with AI, what breaks when you paste it into a chatbot, and the checks that keep keys, placeholders and plurals intact.

by transglot team
published November 23, 2026
8 min read

Documentation reviewed 23 November 2026.

Quick answer

To translate a JSON i18n file with AI, send only the values to the model, keep every key and placeholder unchanged, and validate the result before you commit it. You can do that by hand in a chat assistant for a small file, with a short script against a model API, or with a localization tool that runs the translation and the checks for you. The method matters less than the validation: a JSON file that parses can still ship a broken {count}.

What a JSON locale file looks like

Most JavaScript i18n libraries read one JSON file per language. There are two shapes.

Flat, where the key is the whole path:

jsonjson
{
"home.title": "Welcome back",
"home.greeting": "Hello, {name}!",
"cart.items_one": "{count} item",
"cart.items_other": "{count} items"
}

Nested, where objects group the keys:

jsonjson
{
"home": {
"title": "Welcome back",
"greeting": "Hello, {name}!"
},
"cart": {
"items": "{count, plural, one {# item} other {# items}}"
}
}

Three things in these files are not text to translate: the keys, the placeholders such as {name}, and the plural syntax. Everything that goes wrong comes from a model treating one of them as text.

What goes wrong when you paste JSON into a chatbot

A locale file looks simple, which is why pasting it into an assistant is tempting. Five things break in practice:

  1. Keys get translated. "checkout.title" becomes "kasse.titel" and your app shows the key name.
  2. Placeholders change. {name} becomes {nom}, or %d loses its percent sign.
  3. Plurals are flattened. English has two plural forms, Arabic has six and Japanese has one. A model given one and other returns one and other.
  4. Long files are truncated. The reply stops at the output limit and the closing braces are missing.
  5. Nothing is remembered. The next time one sentence changes, you translate the whole file again and get different wording for strings you had already approved.

Method 1: a chat assistant, for a file under about 100 strings

Paste the file with an instruction that says exactly what must not change:

texttext
Translate the values of this JSON file from English to German.
Do not change any key.
Do not change text inside { }.
Keep ICU plural syntax, and use the plural categories German needs.
Return valid JSON only, with the same keys in the same order.

Then check the result. Compare the key list of the source and the output, and search both for every placeholder. This works for a landing page. It does not scale to a file that changes every week.

Method 2: a script against a model API

A script fixes truncation and repetition. The parts that matter are the ones around the model call, so they are written out here. The model call itself is one function you fill in for your provider.

jsjs
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';
const flatten = (obj, prefix = '') =>
Object.entries(obj).flatMap(([key, value]) =>
typeof value === 'string'
? [[prefix + key, value]]
: flatten(value, `${prefix}${key}.`),
);
const unflatten = (entries) => {
const out = {};
for (const [path, value] of entries) {
const parts = path.split('.');
let node = out;
for (const part of parts.slice(0, -1)) node = node[part] ??= {};
node[parts.at(-1)] = value;
}
return out;
};
const placeholders = (text) => (text.match(/\{[a-zA-Z0-9_]+/g) ?? []).sort().join();
const hash = (text) => createHash('sha256').update(text).digest('hex');
// Fill this in: send { key: sourceText } to your model, get { key: translation } back.
async function translateBatch(batch, locale) {
throw new Error('Call your model API here');
}
async function translateFile(locale) {
const source = flatten(JSON.parse(await readFile('messages/en.json', 'utf8')));
const target = Object.fromEntries(await readJson(`messages/${locale}.json`));
const cache = Object.fromEntries(await readJson(`.i18n-cache/${locale}.json`));
// Only strings that are new or whose English changed.
const todo = source.filter(([key, text]) => cache[key] !== hash(text) || !target[key]);
for (let i = 0; i < todo.length; i += 40) {
const batch = Object.fromEntries(todo.slice(i, i + 40));
const result = await translateBatch(batch, locale);
for (const [key, text] of Object.entries(batch)) {
const translated = result[key];
if (!translated) throw new Error(`${locale}: no translation for ${key}`);
if (placeholders(translated) !== placeholders(text)) {
throw new Error(`${locale}: placeholders changed in ${key}`);
}
target[key] = translated;
cache[key] = hash(text);
}
}
// Write in the source's key order, and drop keys the source no longer has.
const ordered = source.map(([key]) => [key, target[key]]);
await writeFile(`messages/${locale}.json`, JSON.stringify(unflatten(ordered), null, 2) + '\n');
await writeFile(`.i18n-cache/${locale}.json`, JSON.stringify(cache, null, 2) + '\n');
}
async function readJson(path) {
try {
return flatten(JSON.parse(await readFile(path, 'utf8')));
} catch {
return [];
}
}
await mkdir('.i18n-cache', { recursive: true });
for (const locale of ['fr', 'de', 'es']) await translateFile(locale);

What each part is for:

  • flatten and unflatten turn the nested file into key and value pairs and back, so the model never sees the structure and cannot change it.
  • The cache of hashes means a string is sent again only when its English text changes. This is what keeps approved wording stable and the bill small.
  • Batches of 40 keep each reply well under the output limit.
  • The placeholder comparison stops the run when a translation has different placeholders from its source.
  • Writing in source order keeps the diff readable and removes keys you deleted.

What this script does not do: it does not check plural categories per language, it has no glossary, and nobody reviews the output. Add those as the product grows, or move to a tool that has them.

Method 3: a localization tool that does all five steps

This is what a continuous localization tool is for. With Transglot the same loop is one command, run from the repository root:

bashbash
npx transglot@latest init

init finds the locale files, works out the source language, asks which languages you want, and runs the first translation. It writes a transglot.json that names the files:

jsonjson
{
"url": "https://api.transglot.ai",
"sources": [
{ "path": "messages/{locale}.json", "format": "json_nested", "locales": ["en"] }
],
"pull": [
{ "path": "messages/{locale}.json", "format": "json_nested" }
]
}

After that, two commands keep every language current:

bashbash
transglot push --wait
transglot pull

push sends only the strings that changed. pull writes the translated files back in the shape they went in, flat or nested. Four checks run on every string before it is written: placeholders, plural forms, glossary terms and length. A string that fails placeholders, plurals or glossary is repaired once and, if it still fails, refused instead of written. A sentence you have already approved is served from translation memory and is not charged again.

The command line tool needs the Starter plan, at $19 a month for 300,000 translated words. The browser console is on the Free plan and takes a JSON upload directly. See pricing.

Other tools that translate JSON files in a similar loop include Lokalise, Crowdin, Tolgee and SimpleLocalize. Compare how each one counts usage before choosing: the Lokalise, Crowdin, Tolgee and SimpleLocalize comparisons price one workload on each.

Plurals in JSON, the part most scripts get wrong

JSON has no plural construct, so libraries add their own. There are two conventions.

ICU messages keep every form in one string:

jsonjson
{ "items": "{count, plural, one {# item} other {# items}}" }

A translation into Polish needs more categories inside the same string:

jsonjson
{ "items": "{count, plural, one {# element} few {# elementy} many {# elementów} other {# elementu}}" }

Suffix keys, used by i18next, put each form in its own key:

jsonjson
{ "items_one": "{{count}} item", "items_other": "{{count}} items" }

A Polish file then needs items_few and items_many as well, which are keys the English file does not have.

So a correct translation is not always a one-to-one copy of the source keys. With ICU, check that each language's string has the categories it needs. With suffix keys, add the extra keys for languages with more forms. In Transglot, an ICU plural inside a JSON string is read and checked as a plural, while suffix keys are ordinary keys. i18next best practices covers the suffix convention.

A checklist for any method

  • The output has exactly the keys of the source, apart from plural suffix keys a language needs.
  • Every placeholder in a source string is in its translation, spelled the same.
  • Each language has the plural forms it needs, not the forms English has.
  • Unchanged strings were not sent again.
  • The file is valid JSON and has the same nesting as the source.
  • A person who reads the language has looked at the strings users see most.

For checks you can run in continuous integration, see React localization CI checks and automated localization QA.

Frequently asked questions

Can ChatGPT translate a JSON file?

Yes, for a small file, if you tell it to leave keys and placeholders alone and you verify the output. For a file of several hundred strings, the reply is often cut off and the checks become the larger job.

How do I keep the JSON keys from being translated?

Send only the values to the model, or state the rule in the prompt and compare the key lists afterwards. A tool that parses the file never shows the keys to the model as text to translate.

Does flat or nested JSON matter?

Not for translation quality. It matters for the round trip: the file should come back in the structure it had. Transglot reads and writes both, and treats a flat file with spaces in its keys as Laravel JSON.

How much does it cost to translate a JSON file with AI?

A file of 1,000 strings at 8 words each is 8,000 words per language. Through a model API that is usually a few cents to a few dollars per language, depending on the model. On Transglot, 5 languages would be 40,000 translated words, inside the 100,000 words the Free plan starts with.

Should the translated files be committed to the repository?

Usually yes. Committed files are versioned with the code that uses them and reviewed in the same pull request. The alternative is loading translations at runtime, which lets you fix wording without a release. How to translate a React or Next.js app automatically shows both.

How this guide was checked

  • The script in Method 2 was run on a sample file with a stand-in for the model call, to confirm the caching, batching, placeholder check and key order behave as described.
  • The commands and the configuration in Method 3 are taken from the product documentation linked under Sources.
  • The other tools named are listed because they translate JSON files in a similar loop. Their output was not tested for this guide, so it makes no claim about which translates best.
  • Plural categories follow the Unicode CLDR rules linked under Sources.

Sources

colophon

Who wrote this, and what to read next

wrote this

transglot team

The byline on this post has no profile yet. Author profiles are managed alongside the posts themselves.

Engineering
Developer platform
keep reading

i18next best practices for scalable apps

Scale i18next with deliberate namespaces, correct plural lookups, safe interpolation and explicit fallback rules. Includes working examples and a release checklist.

February 3, 2026
6 min read
keep reading

AI Translation API Guide for Software Teams

Use an AI translation API with clear context, validation, retries and review. Compare documented approaches and build a reliable software localization workflow.

August 7, 2026
30 min read
works with what you already run

41 connectors, already built.

the pipeline this post describes

Try it on your own strings. Free, no card.

Free plan: 100,000 words to start (25,000 at sign-up, 75,000 after a phone check), then 10,000 a month, 15 locales including your source, 3 seats.