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

@cocoar/localization

v0.2.1

Published

Localization and language management for the Cocoar Design System

Readme

@cocoar/localization

Complete localization system for the Cocoar Design System.

Overview

This library provides centralized language management, formatting (L10n), and translations (i18n) for Cocoar applications. It serves as the single source of truth for the current language and automatically synchronizes all localization systems.

Features

  • Language Management - Centralized language state with Observable-first API
  • L10n (Localization) - Date, number, currency, percent formatting with browser Intl API + optional HTTP overrides
  • i18n (Internationalization) - Translation system with automatic loading and parameter interpolation
  • Automatic Synchronization - Language changes automatically trigger L10n and i18n updates
  • Reactive API - Observable-first API; Signals are available for Angular template/Signal edges
  • Lightweight - Zero dependencies beyond Angular core and RxJS

Installation

pnpm add @cocoar/localization

Quick Start

Minimal Setup (L10n only)

import { ApplicationConfig } from '@angular/core';
import { provideCoarLocalization } from '@cocoar/localization';

export const appConfig: ApplicationConfig = {
  providers: [
    // Core system: language management + Intl formatting
    provideCoarLocalization({
      defaultLanguage: 'en',
    }),
  ],
};

This gives you:

  • Language management (CoarLocalizationService, Observable-first)
  • Browser Intl API for formatting (date, number, currency, percent)
  • i18n system (but no translation loader)

With HTTP Sources (L10n + i18n)

import { ApplicationConfig } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import {
  provideCoarLocalization,
  provideCoarL10nHttpSource,
  provideCoarI18nHttpSource,
} from '@cocoar/localization';

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(),

    // Core system
    provideCoarLocalization({
      defaultLanguage: 'en',
    }),

    // Optional: L10n HTTP overrides for business rules
    provideCoarL10nHttpSource(),  // Defaults to /locales/{lang}.json

    // Optional: i18n HTTP translations
    provideCoarI18nHttpSource(),  // Defaults to /i18n/{lang}.json
  ],
};
import { Component, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { CoarLocalizationService } from '@cocoar/localization';

@Component({
  selector: 'app-language-switcher',
  template: `
    <div>
      <p>Current language: {{ currentLanguage() }}</p>
      <button (click)="switchToGerman()">Deutsch</button>
      <button (click)="switchToEnglish()">English</button>
    </div>
  `,
})
export class LanguageSwitcherComponent {
  readonly locale = inject(CoarLocalizationService);
  readonly currentLanguage = toSignal(this.locale.languageState.value$, {
    initialValue: this.locale.languageState.value,
  });

  switchToGerman() {
    this.locale.setLanguage('de');
  }

  switchToEnglish() {
    this.locale.setLanguage('en');
  }
}

Using the Observable

import { Component, inject, OnInit } from '@angular/core';
import { CoarLocalizationService } from '@cocoar/localization';

@Component({
  selector: 'app-example',
  template: `<p>Language changes: {{ changeCount }}</p>`,
})
export class ExampleComponent implements OnInit {
  private readonly locale = inject(CoarLocalizationService);
  changeCount = 0;

  ngOnInit() {
    // Subscribe to language changes
    this.locale.languageState.value$.subscribe((newLang) => {
      console.log('Language changed to:', newLang);
      this.changeCount++;
      // Reload data, update formatting, etc.
    });
  }
}

// Note: languageState.value$ emits the current language immediately on subscribe.
// If you only care about subsequent changes, use `skip(1)` in your pipe chain.

Getting Current Language

import { inject } from '@angular/core';
import { CoarLocalizationService } from '@cocoar/localization';

export class MyService {
  private readonly locale = inject(CoarLocalizationService);

  doWork() {
    const currentLang = this.locale.languageState.value;
    console.log('Current language:', currentLang);
  }
}

API

provideCoarLocalization()

Configures the locale system with the default language.

Note: Browser Intl API is automatically included as the first localization source.

function provideCoarLocalization(config: CoarLocalizationConfig): EnvironmentProviders;

interface CoarLocalizationConfig {
  /** The default/fallback language */
  defaultLanguage: string;
}

Example:

provideCoarLocalization({
  defaultLanguage: 'en',
});

CoarLocalizationService

Properties

  • languageState: ReadonlyState<string> - Canonical language state (.value + .value$)

Methods

  • setLanguage(language: string): Promise<void> - Sets the current language (async to load data)
  • getDefaultLanguage(): string - Returns the default language (from config)

Default Configuration

If provideCoarLocalization() is not called, the service uses these defaults:

  • Default language: 'en'
  • L10n source: Browser Intl API (always included automatically)
  • i18n service: Available but no translation loader (use provideCoarI18nHttpSource() to add one)

License

Apache-2.0