# react-locale-hoc

> A higher-order component for React for handling internationalisation.

Latest version **0.2.9** (published 2019-07-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-locale-hoc
pnpm add react-locale-hoc
yarn add react-locale-hoc
bun add react-locale-hoc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2019-07-10 |
| First published | 2018-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Neil Bryson Cargamento |
| Maintainers | neilbryson |
| Keywords | i18n, internationalisation, internationalization, localisation, localization, hoc, higher order component, react |

## Links

- npm: https://www.npmjs.com/package/react-locale-hoc
- Repository: https://github.com/neilbryson/react-locale-hoc
- Issues: https://github.com/neilbryson/react-locale-hoc/issues
- npm.io page: https://npm.io/package/react-locale-hoc

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.2.9 (latest) — 2019-07-10
- 0.2.8 — 2019-07-10
- 0.2.7 — 2019-07-07
- 0.2.6 — 2019-07-07
- 0.2.5 — 2019-07-06
- 0.2.4 — 2019-07-06
- 0.2.3 — 2019-06-22
- 0.2.2 — 2018-12-16
- 0.2.1 — 2018-12-16
- 0.2.0 — 2018-12-16
- 0.1.0 — 2018-12-15

## README

# react-locale-hoc

A higher-order component for React for handling internationalisation.

Wrapped components will receive a `t(stringId)` prop which will return the string 
that it would find in your strings file.

## Requirements
React v16.3 or higher. This uses React's Context API.

## Installation
```bash
  npm install --save react-locale-hoc
```

## Usage
  An object like this could be created to make it easier to pass the strings to the `LocaleProvider`.  
  [Lazy loading](https://webpack.js.org/guides/lazy-loading/) could be implement if you prefer that.
  ```javascript
  // locales.js
  import enUS from './locales/en-US.json';
  import fr from './locales/fr.json';

  const locales = {
    'en-US': enUS,
    'fr': fr,
  };
   
  export default locales;
  ```

  Wrap your root component in the `LocaleProvider` so that all of its descendants could receive `react-locale-hoc`'s context.
  ```javascript
  // App.js
  import React, { PureComponent } from 'react';
  import { LocaleProvider } from 'react-locale-hoc';

  import MyApp from './MyApp';

  import locales from './locales/locales.js';
   
  class App extends PureComponent {
    render() {
      return (
        <LocaleProvider strings={locales}>
          <MyApp />
        </LocaleProvider>
      );
    }
  }
  ```

  The `localise` HOC will provide the `t(stringId)` prop to the wrapped component.
  ```javascript
  // MyComponent.js
  import React, { PureComponent } from 'react';
  import { localise } from 'react-locale-hoc';
   
  class MyComponent extends PureComponent {
    render() {
      return (
        <div>
          <h1>{this.props.t('hello_world')}</h1>
          This component now has access to the localisation strings !
        </div>
      )
    }
  }
   
  export default localise(MyComponent);
  ```

## License
[MIT](/LICENSE)

---
_Source: https://npm.io/package/react-locale-hoc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
