New
Apps 6,246Makers 6,225This week 13
Promote your app−30%
ngx-runtime-i18n screenshot 1
1views in
the last 30 days

ngx-runtime-i18n

A modern runtime internationalisation library for Angular 16+

Built with Claude Code

by ashwinsathian · Unclaimed · from INIndia · added Nov 3, 2026
no ratings0 comments

Signals-first runtime i18n for Angular 16+: SSR-safe, hydration-friendly, ICU-lite, and configurable fallback chains.


Website

The marketing/docs site for this package family lives at apps/site (an Nx Angular application with static prerendering), deployed to Cloudflare Pages at https://i18n.ashwinsathian.com. See apps/site/README.md for local dev, build, and test commands.


Features

  • provideRuntimeI18n() installs I18nService, I18nPipe, and the optional I18nCompatService (RxJS bridge)
  • Deterministic SSR → CSR via TransferState snapshots (see apps/demo-ssr)
  • Per-key fallback chains: active lang → custom fallbacks[] → defaultLang
  • Catalog caching modes: none, memory, or storage (localStorage revalidation)
  • DX helpers: lang() signal plus getCurrentLang(), getLoadedLangs(), and hasKey()
  • Hydration-safe: no DOM mutations before Angular stability

Install

npm i @ngx-runtime-i18n/angular @ngx-runtime-i18n/core

Usage

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRuntimeI18n } from '@ngx-runtime-i18n/angular';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRuntimeI18n(
      {
        defaultLang: 'en',
        supported: ['en', 'hi', 'de'],
        fallbacks: ['de'],
        fetchCatalog: (lang, signal) =>
          fetch(`/i18n/${lang}.json`, { signal }).then((r) => {
            if (!r.ok) throw new Error(`Failed to load catalog: ${lang}`);
            return r.json();
          }),
        onMissingKey: (key) => key,
      },
      {
        localeLoaders: {
          en: () => import('@angular/common/locales/global/en'),
          hi: () => import('@angular/common/locales/global/hi'),
          de: () => import('@angular/common/locales/global/de'),
        },
        options: {
          autoDetect: true,
          storageKey: '@ngx-runtime-i18n:lang',
          cacheMode: 'storage',
          cacheKeyPrefix: '@ngx-runtime-i18n:catalog:',
          preferNavigatorBase: true,
        },
      }
    ),
  ],
};
<!-- Template -->
<h1>{{ 'hello.user' | i18n:{ name: username } }}</h1>
<p>{{ 'cart.items' | i18n:{ count: items().length } }}</p>
<small>Fallback → {{ 'legacy.title' | i18n }}</small>
// Component
import { Component, effect, inject, signal } from '@angular/core';
import { I18nPipe, I18nService } from '@ngx-runtime-i18n/angular';

@Component({
  standalone: true,
  imports: [I18nPipe],
  template: `
    <button (click)="switch('de')">Deutsch</button>
    <div>{{ i18n.t('hello.user', { name: 'Ashwin' }) }}</div>
  `,
})
export class ToolbarComponent {
  i18n = inject(I18nService);
  loaded = signal<string[]>([]);

  constructor() {
    effect(() => {
      this.i18n.lang(); // subscribe to the signal
      this.loaded.set(this.i18n.getLoadedLangs());
    });
  }

  async switch(lang: string) {
    if (this.i18n.ready()) await this.i18n.setLang(lang);
  }
}

Need RxJS? Inject I18nCompatService for lang$, ready$, and t() without signals.


DX helpers

I18nService exposes synchronous utilities for tooling and debugging:

  • getCurrentLang(): snapshot of the active language without reading the signal
  • getLoadedLangs(): list of catalogs currently cached in memory
  • hasKey(key, lang = current): determine if a key exists before rendering

Pair these with Angular effect()/computed() to display diagnostics in dev tools:

const lang = this.i18n.getCurrentLang();
const loaded = this.i18n.getLoadedLangs();
const missingLegacy = !this.i18n.hasKey('legacy.title');

Fallback chains & catalog caching

  • Configure RuntimeI18nConfig.fallbacks?: string[]. Lookup order is active language, then each fallback in order, then defaultLang. Missing keys then flow to onMissingKey.
  • RuntimeI18nOptions.cacheMode controls persistence:
    • none: keep only the active fallback chain in memory
    • memory (default): cache every loaded language for the session
    • storage: hydrate catalogs from localStorage, then refresh them in the background (cacheKeyPrefix controls storage keys)
  • Server environments never touch localStorage; hydration stays deterministic when you seed TransferState.

SSR example

The repo ships with apps/demo-ssr, a full Express + Angular SSR demo. For each request, the server picks a language from ?lang, a lang cookie or Accept-Language, reads the catalogs and passes them to handle() as the request context. provideRuntimeI18nSsr() seeds TransferState from that, and the browser hydrates in the same language. Run it locally:

nx serve demo-ssr                              # dev server, http://localhost:4200
nx build demo-ssr && node dist/apps/demo-ssr/server/server.mjs   # production build, http://localhost:4000

Demos

nx serve demo        # CSR demo with caching + fallbacks
nx serve demo-ssr    # SSR + hydration demo

Catalog JSON lives under apps/demo*/public/i18n/<lang>.json.


Packages

Package Description npm
@ngx-runtime-i18n/core Framework-agnostic primitives (ICU-lite formatter, shared types). Published
@ngx-runtime-i18n/angular Angular wrapper (signals, SSR-safe service, pipes). Published
@ngx-runtime-i18n/primeng Optional PrimeNG adapter that mirrors runtime language changes. Published
@ngx-runtime-i18n/material Optional Angular Material adapter (paginator, sort, stepper, datepicker labels). Published
@ngx-runtime-i18n/schematics ng add schematic that scaffolds provideRuntimeI18n() into an existing project. Published
@ngx-runtime-i18n/cli CLI for extracting translation keys from source and validating catalogs. Published

Docs


License

MIT © Ashwin Sathian

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#angular · #i18n · #library