npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@angular-libs/translate

v0.1.1

Published

A modern, highly performant, Signals-based translation library for Angular 19+.

Readme

@angular-libs/translate

A modern, highly performant, Signals-based translation library specifically built for Angular 19+ and Standalone Components. Fast, strongly typed, and natively supports nested JSON with zero runtime overhead.

npm version

Stackblitz playground

Features

  • ⚡️ Signals First: Built around Angular Signals for minimal change detection loops. Returns computed() signals directly to your template.
  • 🛡️ End-to-End Type Safety: Extract types directly from your JSON files or define strict interfaces for keys and their parameters.
  • 🪶 Lightweight: Tiny core footprint, no transitive dependencies, designed strictly for modern Angular architecture.

1. Setup (`app.config.ts`)

By default, this halts app initialization until translations are loaded to prevent template flickering.

import { provideALTranslate } from '@angular-libs/translate';

export const appConfig = {
  providers: [
    provideALTranslate({
      defaultLang: 'en',
      // The loader runs inside an Injection Context, so you can safely use inject() here if needed.
      loader: (lang) => fetch(`/assets/i18n/${lang}.json`).then((res) => res.json()),

      // Optional: Set to false if you want the app to boot immediately and load languages in the background
      // blockBootstrap: false
    }),
  ],
};

2. Strong Typing (Optional but Recommended)

You can choose between simple key validation or strict parameter validation.

Option A: Read types from your JSON (Simple)

Ensure "resolveJsonModule": true is active in tsconfig.json.

// Use 'import type' to prevent your JSON from being bundled in your JS!
import type enTranslations from '../assets/i18n/en.json';
import { TranslationKeysOf, ALTranslate } from '@angular-libs/translate';
import { inject } from '@angular/core';

// Generates a string union of all nested dot-notation keys
export type AppTranslations = TranslationKeysOf<typeof enTranslations>;

Option B: Strict Interface Mapping (Enterprise)

Map your keys and strictly enforce exactly what parameters each key needs.

export interface AppTranslations {
  'home.title': undefined; // ❌ No parameters allowed
  greeting: { name: string; age?: number }; // ✅ Strict parameters
}

DRY Strategy: The Alias Subclass (Optional)

If you don't want to manually type translate: ALTranslate<AppTranslations> in every single component, you can create an empty subclass and use the useExisting provider directly in its decorator.

import { Injectable } from '@angular/core';
import { ALTranslate } from '@angular-libs/translate';

@Injectable({ providedIn: 'root', useExisting: ALTranslate })
export class AppTranslateService extends ALTranslate<AppTranslations> {}

Now you can just inject AppTranslateService anywhere in your app, no extra app.config.ts providers needed!

3. Usage inside Components

There are three ways to use translations, depending on your needs.

Option A: The Signals Way (Maximum Performance)

This is the most performant approach in Angular 19. It creates a computed Signal that only updates the DOM when the language is explicitly changed. It will skip all default change detection cycles.

import { Component, inject } from '@angular/core';
import { ALTranslate } from '@angular-libs/translate';
import { AppTranslateService } from './translations'; // If using DRY Subclass Strategy

@Component({
  template: `<p>{{ greetingMsg() }}</p>`,
})
export class MyComponent {
  // Option 1: Explicit Typing
  // private translate: ALTranslate<AppTranslations> = inject(ALTranslate);

  // Option 2: Clean Subclass Injection (DRY Strategy)
  private translate = inject(AppTranslateService);

  // Returns a Signal<string>
  greetingMsg = this.translate.select('greeting', { name: 'Alice' });
}

Option B: The Pipe Way (Classic Angular)

For quick template-driven development, you can use the standalone TranslatePipe.

<h2>{{ 'home.title' | translate }}</h2>
<p>{{ 'greeting' | translate: { name: 'Alice' } }}</p>

Option C: The Synchronous Way (For TS Logic)

You can call .get() to retrieve the raw string value immediately in TypeScript. (Note: Avoid binding .get() directly in your HTML templates {{ translate.get('...') }} as it executes on every change detection cycle).

import { Component, inject } from '@angular/core';
import { AppTranslateService } from './translations';

export class MyComponent {
  private translate = inject(AppTranslateService);

  checkError() {
    alert(this.translate.get('error.code', { status: 404 }));
  }
}

Recipes

Changing Language at Runtime

If you provided a loader function in your config, simply call loadLanguage():

import { Component, inject } from '@angular/core';
import { AppTranslateService } from './translations';

export class MyComponent {
  private translate = inject(AppTranslateService);

  switchLanguage(lang: string) {
    this.translate.loadLanguage(lang).then(() => {
      console.log(`Language switched to ${lang}`);
    });
  }
}

Programmatic API (`ALTranslate`)

  • currentLang: A WritableSignal holding the active language code.
  • loadLanguage(lang: string): Promise<void>: Fetches and loads translations for a specific language using the provided loader, then sets it as active.
  • setDictionary(translations: TranslationInput): Replaces the translation dictionary (does not update active lang).
  • get(key, params): Synchronously format a key.
  • select(key, params): Returns a Computed Signal of the translation that updates instantly when the language changes.

Limitations

  • Single dictionary active at a time. Switching language replaces the current dictionary (unless manually merging).
  • No Pluralization rules (e.g. "1 item" vs "2 items"). Use manual logic in your templates or services.
  • No ICU message format. Simple mustache interpolation {{ variable }} only.