# react-stupid-i18n

> A fully type-safe and lightweight React internationalization library for all your TS and JS projects.

Latest version **1.0.2** (published 2023-04-28) · 0 weekly downloads

## Install

```sh
npm install react-stupid-i18n
pnpm add react-stupid-i18n
yarn add react-stupid-i18n
bun add react-stupid-i18n
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-04-28 |
| First published | 2023-04-24 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Eduardo Borges |
| Maintainers | eduardoborges |

## Links

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

## Dependencies (1)

- [@preact/signals-react](https://npm.io/package/@preact/signals-react.md) ^1.3

## Recent versions

- 1.0.2 (latest) — 2023-04-28
- 1.0.1 — 2023-04-28
- 1.0.0 — 2023-04-24

## README

# 🌏 react-stupid-i18n <!-- omit in toc -->

[![NPM](https://img.shields.io/npm/v/react-stupid-i18n.svg)](https://www.npmjs.com/package/react-stupid-i18n) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://standardjs.com) [![Bundle Size](https://badgen.net/bundlephobia/minzip/react-stupid-i18n)](https://bundlephobia.com/result?p=react-stupid-i18n)



- 🤘 100% type-safe, infering all locales keys.
- 🤩 No Provider wrapper needed, powered by [preact signals](https://github.com/preactjs/signals);
- 🏆 Better Developer Experience (DX);
- 🗜 Small bundle;

---

- [Install](#install)
- [Setup](#setup)
- [Using JSON locale files](#using-json-locale-files)

## Install

```bash
npm i react-stupid-i18n
```

## Setup

```typescript
import { createInstance } from 'react-stupid-i18n';

// must have same structure
import en_US from './locales/en_US';
import pt_BR from './locales/pt_BR';

export const {
  t, setLanguage, language, avaliableLanguages,
} = createInstance({
  en_US,
  pt_BR,
}, 'en_US');
```
Your locale files:

`./locales/en_US.ts`:
```json
{
  "hello": "Hi {user}",
  "greetings": {
    "morning": "Good morning {user}",
    "evening": "Good evening {user}",
    "casual": {
      "morning": "Yo, happy morning",
      "afternoon": "Yolo"
    }
  }
}
```

In your app:

```typescript
import React from 'react';
import { t } from './i18n';

function App() {
  return (
    <div className="App">
      {t('greetings.evening', { user: 'Eduardo' })}
    </div>
  );
}
```

## Using JSON locale files

You can use JSON files and be 100% type-safe;

```typescript
// must have same structure
import en_US from './locales/en_US.json';
import pt_BR from './locales/pt_BR.json';
```

You just need to enable `resolveJsonModule` in your tsconfig.json file:


```json
{
  ...
  "compilerOptions": {
    "resolveJsonModule": true,
  },
  ...
}
```

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