New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ngneat/transloco-persist-translations

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngneat/transloco-persist-translations

Persist translations for Angular Transloco

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
501
increased by2.87%
Maintainers
3
Weekly downloads
 
Created
Source

Persist Translations

This plugin provides the functionality of persisting translations to the provided storage.

Installation

npm install @ngneat/transloco-persist-translations

Usage

Import the TranslocoPersistTranslationsModule module into the AppModule, and provide the storage you would like to use:

import {
  TranslocoPersistTranslationsModule,
  PERSIST_TRANSLATIONS_STORAGE
} from '@ngneat/transloco-persist-translations';
import { HttpLoader } from './transloco.loader';

@NgModule({
  imports: [
    ...TranslocoModule,
    TranslocoPersistTranslationsModule.init({
      loader: HttpLoader,
      storage: {
        provide: PERSIST_TRANSLATIONS_STORAGE,
        useValue: localStorage
      }
    })
  ]
})
export class AppModule {}

Note that you should not include the default loader to make it work.

You can also use an async storage. For example, let's install localForage and use IndexedDB:

import {
  TranslocoPersistTranslationsModule,
  PERSIST_TRANSLATIONS_STORAGE
} from '@ngneat/transloco-persist-translations';
import { HttpLoader } from './transloco.loader';
import * as localForage from 'localforage';

localForage.config({
  driver: localForage.INDEXEDDB,
  name: 'Transloco',
  storeName: 'translations'
});

@NgModule({
  imports: [
    ...TranslocoModule,
    TranslocoPersistTranslationsModule.init({
      loader: HttpLoader,
      storage: {
        provide: PERSIST_TRANSLATIONS_STORAGE,
        useValue: localForage
      }
    })
  ]
})
export class AppModule {}

Configuration

TranslocoPersistTranslationsModule can also receive the following configuration:

{
  "ttl": 86400,
  "storageKey": "yourKey"
}
  • ttl: How long the cache should live in seconds.
  • storageKey: The key to be used to save the translations data.

Clear Storage

The storage cleanup is done automatically once the ttl is passed, but it could also can be done manually by calling clearCache method from the cache service:

import { TranslocoPersistTranslations } from '@ngneat/transloco-persist-translations';

export class AppComponent {
  constructor(private loader: TranslocoPersistTranslations) {}

  clearTranslationsCache() {
    this.loader.clearCache();
  }
}

Keywords

FAQs

Package last updated on 27 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc