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

ngx-localized-router

v1.0.0

Published

Angular library that adds multilingual support to the Angular Router by translating route paths based on the active language

Readme

✨ What is ngx-localized-router?

ngx-localized-router is a lightweight Angular library that helps you localize your application routes by adding language segments to the URL.

Examples of supported routes:

/            → default language
/en          → English
/de          → German
/about
/en/about
/de/about

It is built specifically for modern Angular (20+) and designed to work seamlessly with:

  • ✅ Standalone APIs
  • ✅ Angular Signals
  • ✅ Zoneless applications
  • ✅ Server-Side Rendering (SSR)

No hacks, no router monkey-patching — just clean, predictable localization.

🚀 Features

  • 🌐 Language prefixes in URLs (/en, /de, etc.)
  • 🔁 Automatic language detection from the route
  • 🧠 Signal-based APIs
  • 🧩 Standalone-first (no required NgModules)
  • ⚡ Zoneless compatible
  • 🖥️ SSR-safe (Angular Universal / Node / Edge)
  • 🌳 Tree-shakable & lightweight

📦 Installation

npm install ngx-localized-router

🛠️ Setup

ngx-localized-router integrates directly with Angular’s router by patching your routes and providing a small service to track and control the active language.

1️⃣ Provide the localized router

Configure the library using provideNgxLocalizedRouter:

import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideNgxLocalizedRouter, localizeRoutes } from 'ngx-localized-router';

export const appConfig: ApplicationConfig = {
  providers: [
    provideNgxLocalizedRouter({
      defaultLanguage: 'de',
      languages: ['en', 'de'],
      languageResolved: (language: string) => {
        // Set app language, load translations etc...
      },
    }),
    provideRouter(localizeRoutes(appRoutes)),
  ],
};

2️⃣ Wrap your routes with localizeRoutes()

Your original routes stay clean and language-agnostic:

export const appRoutes: Routes = [
  {
    path: '',
    component: HomeComponent,
  },
  {
    path: 'about',
    component: AboutComponent,
  },
];

After localization, the router will automatically support:

/
/about
/en
/en/about

Navigating to /{defaultLanguage} (e.g. /de) automatically redirects to /.

🧠 Accessing Router Language (Signals)

import { inject } from '@angular/core';
import { NgxLocalizedRouterService } from 'ngx-localized-router';

export class HeaderComponent {
  private localizedRouter = inject(NgxLocalizedRouterService);

  language = this.localizedRouter.routeLanguage;
}

Available signals:

  • routeLanguage – currently active language
  • defaultLanguage
  • supportedLanguages

🔔 Reacting to Language Changes

If you prefer an observable-style API:

this.localizedRouter.routeLanguageChanged.subscribe((language) => {
  console.log('Language changed to:', language);
});

This only emits when the language actually changes.

🔗 Localizing URLs Programmatically

this.localizedRouter.localizeUrl('/about', 'en');
// → /en/about

this.localizedRouter.localizeUrl('/en/about', 'de');
// → /about

Notes:

  • Existing language prefixes are automatically removed
  • The default language is never added to the URL

🧵 localizeRoute Pipe (Templates)

For templates, ngx-localized-router provides the localizeRoute pipe, which wraps the same logic as localizeUrl.

This is the recommended way to localize links in templates.

Example

<a [routerLink]="'/about' | localizeRoute : 'en'">
About (EN)
</a>

<a [routerLink]="'/about' | localizeRoute : 'de'">
Über uns (DE)
</a>

You can also pass route segments as an array:

<a [routerLink]="['about', 'team'] | localizeRoute : 'en'">
Team
</a>

What the pipe does

Internally, the pipe delegates to NgxLocalizedRouterService.localizeUrl():

  • Removes an existing language segment (if present)
  • Adds the requested language prefix
  • Omits the prefix for the default language

This ensures consistent URL generation across:

  • Templates
  • Components
  • Services

🌐 SSR & Hydration Friendly

ngx-localized-router is fully SSR-safe:

  • No access to window or document
  • Works with Angular Universal & hydration
  • Deterministic language resolution on server & client

The optional languageResolved callback is invoked once, after the initial navigation:

languageResolved: (language) => {
  // Ideal place to:
  // - initialize translations
  // - sync analytics
  // - preload language-specific data
}

⚡ Zoneless & Signal-First

  • No dependency on zone.js
  • Uses Angular signals internally
  • Plays nicely with zoneless change detection
  • Minimal runtime overhead

🎯 When to Use This Library

Use ngx-localized-router if you want:

  • Clean, SEO-friendly localized URLs
  • No coupling to translation libraries
  • Full control over language resolution
  • Modern Angular patterns only