Flat or nested JSON for translation files?
Both hold the same texts. The choice is about what your i18n library expects and what your team finds easier to read.
Flat
Every key is on one level, with dots as part of the name:
{
"checkout.title": "Checkout",
"checkout.pay_now": "Pay now"
}
Easy to search for and to compare line by line. Fits libraries that treat the key as a plain string.
Nested
The dots become objects:
{
"checkout": {
"title": "Checkout",
"pay_now": "Pay now"
}
}
i18next, ngx-translate, vue-i18n and next-intl read nested files out of the box and look up checkout.title by walking the objects. Grouping by screen or feature also makes a large file easier to browse.
Which to choose
- Use what your library already reads. i18next, ngx-translate and vue-i18n read both: they look a key up as a path first, and then as one whole key.
- next-intl only reads nested files when keys contain dots: it doesn't find a flat key such as
"checkout.title". - In i18next,
keySeparator: falsemakes a dot always part of the key, which suits flat files whose keys contain dots. - If you plan to nest, avoid giving a group's name a text of its own:
checkoutandcheckout.titlecan't both be texts in a nested file.
In Sleekdocs Translate
Keys are stored the same way whichever format you use, and imports accept both: a nested file is read as dotted keys. The project's File format setting, JSON - Flat or JSON - Nested, decides the shape of the files you deploy and export, and the API can return either with format=flat or format=nested.