Skip to content

Commit

Permalink
Added example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
mashpie committed May 24, 2020
1 parent 1fa3689 commit 4339ad3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ i18n.setLocale('de');
__('Hello'); // --> Hallo`
```

#### Some words on `staticCatalog` option

Instead of letting i18n load translations from a given directory you may pass translations as static js object right on configuration. This supports any method that returns a `key:value` translation object (`{ Hello: 'Hallo', Cat: 'Katze' }`). So you might even mix native **json** with **js** modules and parsed **yaml** files, like so:

```js
// DEMO: quickly add yaml support
const yaml = require('js-yaml');
const fs = require('fs');

// configure and load translations from different locations
i18n.configure({
staticCatalog: {
de: require('../../locales/de-as-json.json'),
en: require('../../locales/en-as-module.js'),
fr: yaml.safeLoad(fs.readFileSync('../../locales/fr-as-yaml.yml', 'utf8'));
},
defaultLocale: 'de'
})
```

**NOTE:** Enabling `staticCatalog` disables all other fs realated options such as `updateFiles`, `autoReload` and `syncFiles`

### i18n.init()

When used as middleware in frameworks like express to setup the current environment for each loop. In contrast to configure the `i18n.init()` should be called within each request-response-cycle.
Expand Down

0 comments on commit 4339ad3

Please sign in to comment.