How to translate nested JSON content? One file, different pages content based on keys. #1667
-
Say I have a file called "marketing-pages.json" which has -
Is there any way I can use the keys header & ctaText from page1 in useTranslation's t function? Or another alternative way? Saw this https://www.i18next.com/translation-function/objects-and-arrays but this tells me how to resolve "page1" and get "header" from it but how do I then pass it on to the function for translation? If my website has 50 pages, it might become difficult in the long run to manage so many pages in different lang folders. This is what I'm trying to solve using single categorized json files which include similar structured pages based on keys. Would like to know if there's a better existing solution for this that you guys use. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I highly suggest you do not manage your pages as nested content in a single file. It will cause all of your pages to load all of your content. Simply write a build step script that splits each nested |
Beta Was this translation helpful? Give feedback.
I highly suggest you do not manage your pages as nested content in a single file. It will cause all of your pages to load all of your content.
Simply write a build step script that splits each nested
page1
into a dedicated JSON file, and keep managing the primary content as you already do.