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:
Nested, where objects group the keys:
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:
- Keys get translated.
"checkout.title"becomes"kasse.titel"and your app shows the key name. - Placeholders change.
{name}becomes{nom}, or%dloses its percent sign. - Plurals are flattened. English has two plural forms, Arabic has six and Japanese has one. A model given
oneandotherreturnsoneandother. - Long files are truncated. The reply stops at the output limit and the closing braces are missing.
- 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:
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.
What each part is for:
flattenandunflattenturn 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:
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:
After that, two commands keep every language current:
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:
A translation into Polish needs more categories inside the same string:
Suffix keys, used by i18next, put each form in its own key:
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.