Persist Translations
The @jsverse/transloco-persist-translations plugin provides functionality to cache translations in specified storage. This ensures translations are stored locally and reduces the need for repeated network requests.
Installation
Usage
To enable persistent translations, provide the necessary configuration in your application's Transloco module or config file. Specify the loader and the storage you want to use.
LocalStorage Example
To enable the plugin, include the following provider in your app providers:
Async Storage (IndexedDB) Example
You can use asynchronous storage like IndexedDB with the help of libraries such as localForage
:
Configuration Options
The provideTranslocoPersistTranslations
method supports the following configuration options:
ttl
number
Time-to-live for the cache (in seconds).
storageKey
string
Key to store translation data.
Example:
Clearing the Cache
The cache is automatically cleared when the ttl
expires. However, you can manually clear it using the clearCache
method:
With this plugin, you can optimize your app's translation loading process, reduce network requests, and provide a seamless multilingual experience for your users.
Last updated
Was this helpful?