https://github.com/willfarrell/react-intl-locale
dynamically load locale as needed for `react-intl`
https://github.com/willfarrell/react-intl-locale
Last synced: 5 months ago
JSON representation
dynamically load locale as needed for `react-intl`
- Host: GitHub
- URL: https://github.com/willfarrell/react-intl-locale
- Owner: willfarrell
- License: mit
- Created: 2017-10-25T16:59:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-24T17:39:50.000Z (over 8 years ago)
- Last Synced: 2025-01-19T13:27:14.917Z (over 1 year ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-intl-locale
Dynamically load locale as needed for `react-intl`.
## Install
```bash
$ npm install react-intl-locale
```
## Use
```js
import initLocale, { defaultLocale, getLocale, setLocale, getLocaleMessages } from 'react-intl-locale';
...
initLocale('en-CA', ['fr-CA']);
...
const locale = getLocale();
const messages = getLocaleMessages(['./{locale}.header.json','./{locale}.footer.json']);
...
...
```
## Docs
### initLocale
- defaultLocale (String): Set the default locale to use in the app. default: `en`.
- allowedLocales (String[]): List of locales supported in the app, excluding the defaultLocale, defaultLocale will be added to it.
Using the browsers locale and the locales initialized the best match will be returned for use.
### getLocale
Returns the currently selected locale
### setLocale
Overrides the the current locale, if allowed based in the init.
### getLocaleMessages
- locale (String): Current locale
- paths (String[]): Array to paths to load for locale. Has locale replacement built in `{locale}` and `{language}`. Path names are relative the root of the build folder.