i18next-react-native-async-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

i18next React Native Async Storage

This plugin caches your user's language in React Native's Async storage

Getting Started

Install using:

yarn install i18next-react-native-async-storage

Then pass it to your i18n instance

import AsyncStoragePlugin from 'i18next-react-native-async-storage'

i18n
  .use(AsyncStoragePlugin())

Fallback mechanism

You can pass a fallback function or language to the plugin in case it fails to find the user's language in the local storage (typically on the app's first run):

// With a fallback language
i18n
  .use(AsyncStoragePlugin('en'))

// With a fallback function
const detectUserLanguage = (callback) => {
  return Expo
    .DangerZone
    .Localization
    .getCurrentLocaleAsync()
    .then(lng => { callback(lng.replace('_', '-')); })
}

i18n
  .use(AsyncStoragePlugin(detectUserLanguage))

Package Sidebar

Install

npm i i18next-react-native-async-storage

Weekly Downloads

366

Version

1.0.4

License

MIT

Unpacked Size

3.23 kB

Total Files

5

Last publish

Collaborators

  • 0xclpz