Search code examples
internationalizationi18nextreact-i18next

Documenting/describing translations in i18next?


I'm examining FBT and i18next as options for adding internationalization to a project of mine, and in the i18next docs I can't seem to find any way of indicating in the translation JSON file a more detailed description or context for the text that's being translated. In FBT they have a "description" key associated with each translation that seems to accomplish this purpose. Is there no parallel field or construct that we can use in i18next?

I did notice that keys can be of arbitrary length/structure in i18next, so I'm guessing that one would simply put their description in the key, but I'm also seeing recommendations online that i18next keys should be short and concise, which isn't quite what I'm looking for -- I'd prefer if I could make the description more detailed.


Solution

  • Adding a description/context for an individual i18next key is only possible if you use i18next in combination with its translation management system locize (for example with the help of i18next-locize-backend).

    And then you can use it like this:

    i18next.t(key, defaultValue, tDescription);
    i18next.t(key, { defaultValue, tDescription });