Skip to content

i18n plugin to persist user's language in React Native's Async Storage

Notifications You must be signed in to change notification settings

renatomiguelsantos/i18next-react-native-async-storage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18next React Native Async Storage

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

FORKED

This repo was forked from https://github.com/0xClpz/i18next-react-native-async-storage and updated to use the new async storage project instead of the deprecated ones the original repo is still using.

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))

About

i18n plugin to persist user's language in React Native's Async Storage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%