https://github.com/andria-dev/use-language-map
A react hook for mapping languages to values
https://github.com/andria-dev/use-language-map
Last synced: 3 months ago
JSON representation
A react hook for mapping languages to values
- Host: GitHub
- URL: https://github.com/andria-dev/use-language-map
- Owner: andria-dev
- License: mit
- Created: 2019-04-13T16:40:01.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-16T22:38:34.000Z (almost 6 years ago)
- Last Synced: 2025-03-23T04:25:40.544Z (over 1 year ago)
- Language: JavaScript
- Size: 799 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# useLanguageMap
A React hook for mapping words to the active language's words.
# How to use:
## Installation
```bash
yarn add use-language-map
# or
npm install use-language-map
```
## Import
```js
import { useLanguageMap } from 'use-language-map';
// or
const { useLanguageMap } = require('use-language-map');
```
## Usage
```jsx
/**
* YOU MUST DEFINE THE LANGUAGE MAP OUTSIDE THE COMPONENT,
* or memoize it
* Failure to do so will cause infinite re-rendering
*/
const languageMap = {
de: {
of: 'von',
pages: 'Seiten'
},
es: {
of: 'de',
pages: 'páginas'
}
};
function MyComponent() {
const t = useLanguageMap(languageMap, { isPrecise: false });
return (
1 {t('of')} 4 {t('pages')}
);
}
```