# min-react-i18n

> 最小的react国际化库，大小不到1kb，国际化内容会过滤敏感内容，防止js代码注入攻击

Latest version **1.0.1** (published 2022-11-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install min-react-i18n
pnpm add min-react-i18n
yarn add min-react-i18n
bun add min-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 | 1.0.1 |
| Published | 2022-11-10 |
| First published | 2022-08-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | a903529487 |
| Keywords | js, react, i18n, 国际化 |

## Links

- npm: https://www.npmjs.com/package/min-react-i18n
- Repository: https://gitee.com/liangbairong/min-react-i18n
- npm.io page: https://npm.io/package/min-react-i18n

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-11-10
- 1.0.0 — 2022-09-02
- 0.3.0 — 2022-08-29
- 0.2.0 — 2022-08-29
- 0.1.0 — 2022-08-29
- 0.0.1 — 2022-08-29

## README

# min-react-i18n

最小的react国际化库，大小不到1kb，国际化内容会过滤敏感内容，防止js代码注入攻击

### 使用方法

初始化
```javascript
import reactI18n from "min-react-i18n";

const lang='zh-cn'

useEffect(() => {
    setInitDone(false);
    const url = '/i18n/' + lang + '/index.json'
    fetch(url)
        .then(response => response.json())
        .then(json => {
            // json {
            //     "Totheformerone": "你的名字是 {value}",
            // }
            reactI18n.init(json)
        });

}, [currentLocale]);

```


Text组件
```javascript
import React, {FC, useEffect, useState} from 'react';
import reactI18n from "min-react-i18n";

/**
 * i18nKey: 必须，国际化key
 * options：非必须，国际化参数
 */
const Text= ({
                                  i18nKey,
                                  options = {},
                                  children=''
                              }) => {
    const [html, setHtml] = useState<any>('')
    useEffect(() => {
        setHtml(reactI18n.get(i18nKey,options) || children)
    }, [i18nKey])
    return <span dangerouslySetInnerHTML={{__html: html}}/>

}

export default Text

```

使用
```javascript
<Text i18nKey='Totheformerone' options={{value:'小明'}}>内容</Text>  // 你的名字是 小明
```

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