Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaces added via addResourceBundle after init to localstorage/cache #43

Open
cemalokten opened this issue Nov 18, 2022 · 1 comment

Comments

@cemalokten
Copy link

cemalokten commented Nov 18, 2022

Is it possible to store namespaces that are added after init via addResourceBundle in localstorage?

I asked the question on stackoverflow and have not had an answer.


Question posted on stackoverflow: https://stackoverflow.com/questions/74475045/addresourcebundle-after-init-and-cacheing

I am fetching namespaces for each component from a database that store JSON and adding them via addResourceBundle after init:

    // Component
          i18next.addResourceBundle('ar', 'topicNS', {
            topics,
          });

I would like to add these to the cache/localstorage. I am using the localStorageBackend to cache the static JSON resources, how can I add to the cached namespaces after init?

I have tried using the resourcesToBackend plugin, but am not sure how to make it work.

    // i18n.js
        backend: {
          backends: [
            LocalStorageBackend,
            HttpApi,
            resourcesToBackend((language, namespace, callback) => {
              // ???????
            }),
          ],
          loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
        },
@adrai
Copy link
Member

adrai commented Nov 18, 2022

i18next-resources-to-backend is used mainly as fallback backend... for example if your http backend did not serve the translations... I don't know your use case but if your translations (those you are currently adding via addResourceBundle) are not lazy loaded i18next-resources-to-backend should work as expected, like described in the readme.

If that's not what you're looking for (but I really don't know why), you could directly invoke the save function of the local storage backend... but this is really a hack and not an official interface:
i18next.services.backendConnector.backend.backends[0].save('ar', 'topicNS, { topics })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants