# react-native-setlang

> set multiple langs

Latest version **0.1.3** (published 2021-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-setlang
pnpm add react-native-setlang
yarn add react-native-setlang
bun add react-native-setlang
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2021-09-23 |
| First published | 2021-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | doenes24 |
| Maintainers | doenes24 |
| Keywords | react-native, ios, android |

## Links

- npm: https://www.npmjs.com/package/react-native-setlang
- Repository: https://github.com/doenes24/react-native-setlang
- Homepage: https://github.com/doenes24/react-native-setlang#readme
- Issues: https://github.com/doenes24/react-native-setlang/issues
- npm.io page: https://npm.io/package/react-native-setlang

## Dependencies (1)

- [react-native-localize](https://npm.io/package/react-native-localize.md) ^2.1.4

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2021-09-23
- 0.1.2 — 2021-09-23
- 0.1.1 — 2021-09-22
- 0.1.0 — 2021-09-22

## README

# How to install
`yarn add react-native-setlang`  
or  
`npm i react-native-setlang` 
# How it works
So simply.
###### translate.ts
```typescript
import setLang from 'react-native-setlang';

const en = {
  "welcome": "Hello world",
};
const fr = {
  "welcome": "Bonjour le monde",
};

export default new setLang({fr,en});
```
###### App.tsx
```typescript
import userLang from './translate';

const welcomeText = userLang.t("welcome");

console.log(welcomeText);
// 'Hello world' or 'Bonjour le monde'
```
## If user has no language preference ?
No problem :), if user has not language preference, SetLang will chooses the english version of your Objects. If you do not have an english version, it will choose the first one of your Object you setted in `new setLang({fr,en})`.
## If user has those preference: "en", "fr". And I just have a translation for "es" ?
No choice, SetLang will uses es version.

## How to use it correctly ?
Make a translation repository:
```
src/
    translation/
      index.ts
      en.ts
      fr.ts
    App.tsx
```
#### Next
In your **index.ts** you write something like this:
```typescript
import en from './en';
import fr from './fr';
import setLang from 'react-native-setlang';
export default new setLang({en,fr});
```

In **en.ts** and/or **fr.ts**
```typescript
export default {
  like: 'J\'aime',
};
```
And in **App.tsx**
```typescript
import ul from './translation';
// OR
// import userLang from './translation'

const iLike = ul.t('like');
```

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