Registry / storage / i18next-async-storage-backend2

i18next-async-storage-backend2

JSON →
library2.1.0jsnpmunverified

A caching layer backend for i18next that stores and retrieves translation resources using React Native AsyncStorage. Version 2.1.0 (stable, actively maintained) leverages @react-native-async-storage/async-storage for reliable persistent storage. It is designed for React Native apps using i18next, often combined with i18next-chained-backend to fallback to an async resource loader like XHR. Key differentiators include configurable expiration time, version-based cache control, and namespace-level cache skipping. It requires manual installation of the peer dependency @react-native-async-storage/async-storage and ships TypeScript types.

npm install i18next-async-storage-backend2
INSTALL
IMPORT
SIG · I18NEXT-ASYNC-STOR
I
i18next-async-storage-backend2
storagejavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncStorageBackend
import AsyncStorageBackend from 'i18next-async-storage-backend2'
const AsyncStorageBackend = require('i18next-async-storage-backend2')
Default export; CommonJS require also works but ESM is preferred for bundlers.
default import as backend in chained backend config
import AsyncStorageBackend from 'i18next-async-storage-backend2'; // use as: backends: [AsyncStorageBackend]
import { AsyncStorageBackend } from 'i18next-async-storage-backend2'
This package exports a single default constructor, not a named export. Named import will result in undefined.
TypeScript usage
import AsyncStorageBackend from 'i18next-async-storage-backend2'; // types are included
import * as AsyncStorageBackend from 'i18next-async-storage-backend2'
TypeScript definitions are bundled; no @types package needed. Star import not recommended.

Basic setup with i18next-chained-backend using AsyncStorage as primary cache and XHR fallback.

import i18next from 'i18next'; import Backend from 'i18next-chained-backend'; import AsyncStorageBackend from 'i18next-async-storage-backend2'; import XHR from 'i18next-xhr-backend'; i18next.use(Backend).init({ lng: 'en', fallbackLng: 'en', backend: { backends: [AsyncStorageBackend, XHR], backendOptions: [ { prefix: 'i18next_res_', expirationTime: 7 * 24 * 60 * 60 * 1000, versions: {}, skipCache: [] }, { loadPath: '/locales/{{lng}}/{{ns}}.json' } ] } }); export default i18next;
Debug
Known issues
breakingVersion 2.0+ changed backend storage from react-native's built-in AsyncStorage to @react-native-async-storage/async-storage.
fix
Install @react-native-async-storage/async-storage as a dependency: npx expo install @react-native-async-storage/async-storage
affects: >=2.0.0
deprecatedThe package name 'i18next-async-storage-cache' is the original name; 'i18next-async-storage-backend2' is the renamed version.
fix
Use 'i18next-async-storage-backend2' instead of 'i18next-async-storage-cache'.
affects: >=2.0.0
gotchaThe backend must be used with i18next-chained-backend as a primary cache; it cannot serve as a standalone loader for initial translations.
fix
Always pair with a fallback backend like i18next-xhr-backend or i18next-http-backend.
affects: *
gotchaExpirationTime does not reset on read; it is checked when the resource is requested. Changing expirationTime later will affect existing cache entries.
fix
Set expirationTime appropriately at initialization and avoid changing it later to prevent unexpected cache behavior.
affects: *
gotchaVersions object works alongside expirationTime; a version mismatch will not refresh cache if expirationTime hasn't passed.
fix
Either set expirationTime to a long duration or implement manual cache invalidation via version changes.
affects: *
Errors
Common errors & fixes
Cannot find module '@react-native-async-storage/async-storage' or its corresponding type declarations.
Missing peer dependency @react-native-async-storage/async-storage.
fix
Install the peer dependency: npm install @react-native-async-storage/async-storage
TypeError: (0 , _i18nextAsyncStorageBackend2.default) is not a constructor
Using named import instead of default import.
fix
Change import to: import AsyncStorageBackend from 'i18next-async-storage-backend2'
i18next::backendConnector: loading namespace translation failed for language en using backend async-storage-backend
AsyncStorageBackend is used as the only backend but has no data and no fallback.
fix
Add a fallback backend (e.g., i18next-xhr-backend) and configure i18next-chained-backend.
AsyncStorage is not available. Please install @react-native-async-storage/async-storage.
AsyncStorage not imported or initialized in React Native environment.
fix
Ensure @react-native-async-storage/async-storage is installed and linked correctly (in Expo it's auto-linked).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
@react-native-async-storage/async-storagerequiredPeer dependency required for AsyncStorage implementation
Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources