1.1.12 • Published 2 months ago

@universal-packages/localization-react v1.1.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Localization React

npm version Testing codecov

React bindings for Localization.

Install

npm install @universal-packages/localization-react

Localization react uses exclusively the react hooks API so make sure you are using a recent version of React.

Provider

Make sure you wrap your application with the LocalizationProvider so the localization object is available for all components in the tree.

import { LocalizationProvider } from '@universal-packages/localization-react'

const App = () => {

  return <LocalizationProvider dictionary={dictionary} defaultLocale="es-ES">
    /** Some other components */
  <LocalizationProvider>
}

Hooks

useLocalization()

Gets the context provided instance of the localization.

import { useLocalization } from '@universal-packages/localization-react'

const HappyComponent = () => {
  const localization = useLocalization()

  const handleClick = (): void => {
    localization.setLocale('es_MX')
  }

  return (
    <div>
      <button onClick={handleClick}>Change Locale</button>
    </div>
  )
}

useTranslate(subject: String, [locales: Object])

Observes localization changes and returns a function to use to translate the provided subject.

import { useTranslate } from '@universal-packages/localization-react'

const HappyComponent = () => {
  const translate = useTranslate()

  return (
    <div>
      <h1>{translate('happy.title')}</h1>
      <p>{translate('happy.content')}</p>
    </div>
  )
}

Typescript

This library is developed in TypeScript and shipped fully typed.

Contributing

The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.

License

MIT licensed.

1.1.12

2 months ago

1.1.11

2 months ago

1.1.10

2 months ago

1.1.9

3 months ago

1.1.8

3 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.1

8 months ago

1.1.4

6 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.0

11 months ago

1.0.0

11 months ago