Registry / devops / ngx-translate-cache

ngx-translate-cache

JSON →
library20.0.0jsnpmunverified

Angular 20 library (latest v20.0.0, peer dep @angular/core ^20) extending @ngx-translate/core with language caching support. Caches translations in localStorage/sessionStorage to avoid repeated network requests. Releases follow Angular major versions (8-20). Simpler alternative to localize-router for caching only. Requires @ngx-translate/core >=14.0.0. ESM-only, ships TypeScript types.

npm install ngx-translate-cache
INSTALL
IMPORT
SIG · NGX-TRANSLATE-CACH
N
ngx-translate-cache
devopsjavascriptv20.0.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.

TranslateCacheModule
import { TranslateCacheModule } from 'ngx-translate-cache';
import { TranslateCacheModule } from '@ngx-translate/cache';
Package name is ngx-translate-cache, not under @ngx-translate scope. ESM-only, no CommonJS.
TranslateCacheService
import { TranslateCacheService } from 'ngx-translate-cache';
const TranslateCacheService = require('ngx-translate-cache').TranslateCacheService;
ESM-only since v20; require() throws ERR_REQUIRE_ESM.
TranslateCacheSettings
import { TranslateCacheSettings } from 'ngx-translate-cache';
import { TranslateCacheSettings } from 'ngx-translate-cache/settings';
All exports from package root; no subpath exports.

Shows setup of AppModule with TranslateCacheModule.forRoot() with AoT-compatible factory and component initialization calling cache.init().

import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { TranslateCacheModule, TranslateCacheSettings, TranslateCacheService } from 'ngx-translate-cache'; import { AppComponent } from './app.component'; export function TranslateCacheFactory(translateService: TranslateService, translateCacheSettings: TranslateCacheSettings) { return new TranslateCacheService(translateService, translateCacheSettings); } @NgModule({ imports: [ BrowserModule, TranslateModule.forRoot(), TranslateCacheModule.forRoot({ cacheService: { provide: TranslateCacheService, useFactory: TranslateCacheFactory, deps: [TranslateService, TranslateCacheSettings] } }) ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} // In component: import { Component } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { TranslateCacheService } from 'ngx-translate-cache'; @Component({ selector: 'app', template: '{{ "HELLO" | translate }}' }) export class AppComponent { constructor(translate: TranslateService, cache: TranslateCacheService) { translate.setDefaultLang('en'); cache.init(); translate.use('en'); } }
Debug
Known issues
breakingVersion 20 requires Angular 20 and ESM-only; no CommonJS support.
fix
Ensure your project uses Angular 20 and is configured for ESM (set "type": "module" in package.json or use .mjs extension).
affects: >=20.0.0
deprecatedOlder versions (≤19) support both CJS and ESM but Angular major version must match.
fix
Upgrade to matching Angular version or migrate to ESM-only setup.
affects: <20.0.0
gotchaRequires @ngx-translate/core >=14.0.0; incompatible with older versions.
fix
Update @ngx-translate/core to version 14 or later.
affects: >=20.0.0
gotchaTranslateCacheModule.forRoot() must be called exactly once; using it in child modules causes runtime errors.
fix
Only call TranslateCacheModule.forRoot() in AppModule; use TranslateCacheModule (without forRoot) in feature modules if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Can't resolve 'ngx-translate-cache'
Package not installed or wrong version.
fix
Run 'npm install ngx-translate-cache@20 --save' and verify node_modules contains the package.
Error: require() of ES Module /node_modules/ngx-translate-cache/index.mjs not supported
Using CommonJS require() to load an ESM-only module.
fix
Change to ESM import syntax: 'import { TranslateCacheService } from 'ngx-translate-cache';' or set 'type': 'module' in package.json.
NullInjectorError: No provider for TranslateCacheService!
TranslateCacheService not provided via TranslateCacheModule.forRoot().
fix
Ensure AppModule imports TranslateCacheModule.forRoot({cacheService:...}) with factory as shown in docs.
Error: The pipe 'translate' could not be found
TranslateModule not imported or not properly configured.
fix
Import TranslateModule.forRoot() in AppModule and add to imports.
Upgrade
Version history
20.0.0latest on npm
Audit
Dependencies
@angular/commonrequiredpeer dep for Angular 20
@angular/corerequiredpeer dep for Angular 20
@ngx-translate/corerequiredpeer dep >=14.0.0, core translation functionality
Agent activity
16 hits · last 30 days
node
16
Resources
ngx-translate-cache — npm install ngx-translate-cache · libregistry