JSON Localization: What Can Be Translated, and What Must Never Be Touched
The buttons on the page were translated into English, but the program could not find its configuration items. This failure often comes from JSON localization, where every string in an object was sent to the translator, so keys, routes, and business codes changed too. A safer approach is not to guess which strings look like natural language, but to explicitly specify which paths may be translated.
Key points of this article
- When translating JSON, limit the scope by field path so that keys, routes, and business codes are not accidentally changed.
- Determine the list of translatable paths before translation begins. The party generating the translation should not expand the scope of changes.
- During acceptance, in addition to checking the translation, confirm that the set of keys, the unauthorized paths, and the field types have not changed.
- After array elements are reordered, indexes may become invalid. When stable IDs are available, use the IDs as the basis for mapping in preference to indexes.
nullshould not be replaced with text. Duplicate keys must be rejected during the parsing stage, rather than checked after translation is finished.
JSON localization often fails in a specific way: the page buttons have become English, but the program can no longer find the matching configuration items. The usual cause is that every string in the object is sent to the translator, so key names, routes, and business codes change along with the text. This article is for developers and localization staff who manage internationalization configuration. It explains how to first define the translatable field paths and then carry out acceptance checks.
Before processing important documents, keep the original files and review them against the boundaries and acceptance items described in the text.
Which parts of JSON can be translated during localization? One-sentence conclusion
Translate only the copy paths listed in advance, keep key names, route values, and business codes unchanged, and use an acceptance checklist to confirm that the parts that were not meant to change really did not change.
| Your situation | Recommended Practices | Cause |
|---|---|---|
UI copy, e.g. buttons.save | Add to the allowed paths list; confirm before translating. | The path is an explicit address, which is more reliable than guessing whether a string sounds like human language. |
| Routing value, business code | Keep as is; not included in the translation scope | The program depends on these values; after changing them, configuration items may fail to be found. |
| Placeholders, HTML fragments, and URLs in the copy field | Add another layer of protection rules | Fields within the allowed paths may still contain content that needs to be protected. |
| Array elements | Use ID mapping when stable IDs are available. | After elements are reordered, an index may point to a different piece of copy. |
| The path disappears after the source file is updated | Reports the error and updates the source version; does not automatically write back the old translation. | Similar field names may cause translations to be placed in the wrong location. |
Start from field paths, not by traversing every string
Treat buttons.save as an address; replacing on seeing the string "保存" is more reliable. The same sentence may appear in UI copy, log samples, and test cases at once, and all three may not need translation.
The path should use a tuple or an unambiguous representation such as JSON Pointer. If keys are simply joined with dots, ambiguity arises when a key name itself contains a dot.
The example below restricts itself to two specific paths; everything else is kept as-is. This is the localization strategy for this document, not a requirement of the JSON format itself. The synthetic sample contains both interface text and a routing value that must never be changed, to make the boundaries easy to check.
Change only explicitly allowed values at a time
import copy
source = {"buttons": {"save": "保存", "cancel": "取消"},
"route": "/settings", "version": 1}
approved = {("buttons", "save"): "Save",
("buttons", "cancel"): "Cancel"}
def apply_texts(document, replacements):
result = copy.deepcopy(document)
for path, translated in replacements.items():
if not path or not isinstance(translated, str):
raise ValueError("invalid replacement")
parent = result
for key in path[:-1]:
parent = parent[key]
key = path[-1]
if key not in parent or not isinstance(parent[key], str):
raise ValueError("target must be an existing string")
parent[key] = translated
return result
result = apply_texts(source, approved)
assert result["buttons"]["save"] == "Save"
assert result["route"] == source["route"]
assert source["buttons"]["save"] == "保存"
try:
apply_texts(source, {("version",): "one"})
except ValueError:
pass
else:
raise AssertionError("numeric field must be rejected")
The example only demonstrates object hierarchy; it does not implement array indexing and does not call a translation service. When submitted to a real pipeline, the list of allowed paths should be determined before translation, and the party generating the translation should not be able to expand its own scope of changes.
Deep copying prevents the input object from being modified in place, but it is not a transactional system. Persistence still needs to be designed separately.
Acceptance should look at the parts that weren't changed
| Check | Normal result | Actions in case of abnormality |
|---|---|---|
| Key name set | Consistent with the source file | Prevent overwriting the original file |
| Unauthorized path | Value remains unchanged | Find out-of-bounds modifications |
| Target field type | Still a string | Reject Implicit Type Conversion |
| Missing path | Explicit error | Update the source version without automatically creating fields |
Verifying only that "the target language appeared" is not enough. The source file hash and path inventory should also be saved. If a path has been deleted after the source file was updated, the old translation must not be written back automatically based on similar field names.
Arrays, null values, and duplicate keys need to be considered separately
- Arrays: After elements are reordered, an index may no longer point to the same piece of copy. When a stable ID exists, prefer using the ID for mapping.
- Null values:
nullis not an empty string, and it should not be replaced with the word "empty" just for convenience in translation. - Duplicate keys: After ordinary JSON parsing completes, information about duplicate keys may already have been lost. If you want to reject duplicate keys, handle it during the parsing stage rather than checking after translation is finished. See Python JSON Document.
This example suits localizing configuration with a clear structure, not an arbitrary JSON auto-translator. During translation acceptance, first confirm that the structure and protected fields have not changed, and only then discuss whether the language reads naturally. The troubleshooting order will be clearer that way.
📊 Core Comparison
| Method | Method | Main risks | Application Scenarios |
|---|---|---|---|
| Iterate over all strings | Every string is passed to the translator. | Key names, routes, and business codes may all be changed together. | Not covered in the original text. |
| Field path whitelist | Only translate the paths listed in advance. | Need to maintain a list of paths | Structured configuration localization |
🎯 Which Approach Suits You?
If you...
- Maintain the UI configuration file so that button labels can be translated while program configuration stays unchanged. Use a whitelist of field paths, and finalize the path list before translation begins.
- Array elements may be reordered, so map them by stable IDs rather than by index.
- The source file will keep being updated. Save the source file's hash and the path list. If a path disappears, raise an error instead of automatically writing back the old translation.
- For real document delivery, turn the allowed paths, source text, and translations into a review checklist, and check each item one by one.
❓ Frequently Asked Questions (FAQ)
1. Why not just translate all the strings in the JSON?
Because the same string may serve as interface copy, a program key name, or a business code at the same time, sending every string through the translator may also alter key names, routes, and business codes, causing the program to fail to find its configuration items.
2. What's wrong with concatenating paths using dots?
If a key name itself contains a dot, dot-notation concatenation becomes ambiguous. The original text suggests using an unambiguous representation such as a tuple or JSON Pointer.
3. Only check whether the translation contains enough target-language text?
Not enough. You should also check whether the set of key names matches the source file, whether values at unauthorized paths remain unchanged, whether the target fields are still strings, and whether missing paths are explicitly reported as errors.
4. Can null be replaced with the word "空"?
No. null is not an empty string, and it should not be replaced with text just for the convenience of translation.
5. What should be used as the mapping when translating arrays?
When a stable ID is available, prefer using the ID for mapping. Relying only on indexes may cause text to be matched to the wrong element after the elements are reordered.
📝 Summary
Before translating a JSON configuration, first define which paths are allowed to be translated, then use a checklist to verify that everything else is unchanged. This makes problems easier to locate when errors occur.
Try it now: upload a document and start translating right away, with the original layout preserved.


