Open tonix-tuft opened 5 years ago
no...it's an implementation detail of the choosen UI framework -> eg. for react react-i18next takes care for loading them before accessing.
makes no sense to try loading them after calling t('chat:key')
as at that point you already rendered the missing key value -> so lazy loading needs to happen before -> which obviously is totally out of our control (i18next.loadNamespace can be used in userland)
Therefore, the only solution is to make i18next load everything initially with this configuration:
...
.init({
...
ns: ['common', 'chat'], // <---- Explicitly added the namespace
defaultNS: 'common',
...
...
Right?
And everytime I introduce a new namespace, I just append it to the ns
array (e.g.: ns: ['common', 'chat', 'new123']
), correct?
That's just not lazy loading...like said...load them on demand with i18next.loadNamespaces - like eg. https://github.com/i18next/react-i18next/blob/master/src/useTranslation.js#L90
Hi,
I have configured i18next this way using the
backend
plugin:The backend plugin loads the
common
namespace initially right after the page is ready, but I also have created achat
namespace file which I would like to load lazily.If I call
t('chat:key')
in my code, i18next doesn't load the chat namespace file and the string is not translated.I can of course add
chat
tons
like this:But then
i18next
loads thechat
namespace together with thecommon
namespace right after the page loads, and I do not want it because I would like to loadchat
only if there's at least one call tot
with that namespace in the page (i.e. lazy load), e.g. when I callt('chat:key')
it would be great ifi18next
internally checked whether it has already loaded thechat
namespace or not, and if it hasn't, load it through the backend plugin.Is there a way to achieve that?