# @halliday/react-i18n

> This library provides some simple functions to add multi-language support (internationalization) to your React app.

Latest version **2.0.3** (published 2023-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @halliday/react-i18n
pnpm add @halliday/react-i18n
yarn add @halliday/react-i18n
bun add @halliday/react-i18n
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2023-01-03 |
| First published | 2022-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | j.forster |

## Links

- npm: https://www.npmjs.com/package/@halliday/react-i18n
- Repository: https://github.com/halliday/react-i18n
- Homepage: https://github.com/halliday/react-i18n#readme
- Issues: https://github.com/halliday/react-i18n/issues
- npm.io page: https://npm.io/package/@halliday/react-i18n

## Recent versions

- 2.0.3 (latest) — 2023-01-03
- 2.0.2 — 2022-11-11
- 2.0.1 — 2022-09-28
- 1.1.0 — 2022-09-28
- 1.0.0 — 2022-09-28

## README

# React internationalization (i18n) helper

This library provides some simple functions to add multi-language support (internationalization) to your React app.

Easy eaxmple:

```tsx
import {loadLanguage, config as i18nConfig} from '@halliday/react-i18n';

// define your supported languages
// each language must have a file at "/i18n/{lang}.json"
i18nConfig.supportedLanguages = ['en', 'de'];

const container = document.getElementById('root') as HTMLElement;
const root = ReactDOM.createRoot(container);

// load language file
loadLanguage().then(() => {

    // render app when language is loaded
    root.render(<App />);
});

```

A language file must look like this:

- _/i18n/en.json_

```json
{
    "hello": "Hello!",
    "welcome": "Welcome to my app.
}
```

 - _/i18n/de.json_ (German)

```json
{
    "hello": "Hallo!",
    "welcome": "Willkommen in meiner App.
}
```

Now you can use the translations in your code:

```tsx
import { L } from "@halliday/react-i18n";

function WelcomeBanner() {
    return <div>
        <h1>{L('hello')}</h1>
        <p>{L('welcome')}</p>
    </div>;
}
```

## Functions

### `L(key: string)`

Loads the value associated with `key` from the current language file.


### `loadLanguage(): Promise<void>`

Load the current language file from `"/i18n/{lang}.json"`. This function must be called exactly once and before any `L` call is made.

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