Skip to content

Commit

Permalink
Update README.md (#9)
Browse files Browse the repository at this point in the history
I changed the simple example to help new adopters understand when something goes wrong. The simple example will now console log the i18next failedLoading message. I also added two sentences clarifying that the dynamic import cannot be passed a variable.
  • Loading branch information
Clearmist authored Feb 1, 2024
1 parent f64e73e commit 616e186
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ $ npm install i18next-resources-to-backend

## simple example - dynamic imports (lazy load in memory translations)

i18next-resources-to-backend helps to transform resources to an i18next backend. This means, you can also lazy load translations, for example when using webpack:
i18next-resources-to-backend helps to transform resources to an i18next backend. This means you can lazy load translations.

The dynamic import must be passed a string. Webpack will fail to load the resource if you pass a variable to `import()`.

For example, when using webpack:

```js
import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';

i18next
.use(resourcesToBackend((language, namespace) => import(`./locales/${language}/${namespace}.json`)))
.on('failedLoading', (lng, ns, msg) => console.error(msg);
.init({ /* other options */ })
```
Expand Down

0 comments on commit 616e186

Please sign in to comment.