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

@xtaskjs/internationalization

v1.0.3

Published

Internationalization integration for xtaskjs.

Downloads

131

Readme

@xtaskjs/internationalization

Internationalization integration package for xtaskjs.

This package is part of the xtaskjs project, hosted at xtaskjs.io.

Installation

npm install @xtaskjs/internationalization reflect-metadata

What It Provides

  • Request-aware translations with locale fallback.
  • Pluralization with Intl.PluralRules, including exact-count matches like =0.
  • Async namespace loading for feature-specific translation bundles.
  • Currency and date formatting using the active locale, currency, and timezone.
  • Container tokens and decorators for injecting the internationalization service or lifecycle manager.
  • Lifecycle integration so locale services are ready before controllers and services are instantiated.

Register Configuration And Locales

import {
  configureInternationalization,
  registerInternationalizationLocale,
} from "@xtaskjs/internationalization";

configureInternationalization({
  defaultLocale: "en-US",
  fallbackLocale: "en-US",
  defaultCurrency: "USD",
  defaultTimeZone: "UTC",
});

registerInternationalizationLocale({
  locale: "en-US",
  currency: "USD",
  timeZone: "UTC",
  translations: {
    checkout: {
      total: "Total: {{amount}}",
    },
  },
});

registerInternationalizationLocale({
  locale: "es-ES",
  currency: "EUR",
  timeZone: "Europe/Madrid",
  translations: {
    checkout: {
      total: "Total: {{amount}}",
    },
  },
});

Inject And Use The Service

import { Service } from "@xtaskjs/core";
import {
  InjectInternationalizationService,
  InternationalizationService,
} from "@xtaskjs/internationalization";

@Service()
class CheckoutPresenter {
  constructor(
    @InjectInternationalizationService()
    private readonly intl: InternationalizationService
  ) {}

  presentTotal(total: number) {
    return this.intl.t("checkout.total", {
      params: {
        amount: this.intl.formatCurrency(total),
      },
    });
  }
}

Template Formatting Helpers

Translation templates can format numbers, currencies, dates, and datetimes inline.

registerInternationalizationLocale({
  locale: "en-US",
  translations: {
    invoice: {
      summary:
        "Total {{amount, currency}} for {{quantity, number}} items on {{issuedAt, date, dateStyle=long}}",
    },
  },
});

intl.t("invoice.summary", {
  params: {
    amount: 1234.5,
    quantity: 3,
    issuedAt: new Date(),
  },
});

Supported helpers:

  • {{ value, number }}
  • {{ value, currency }}
  • {{ value, date }}
  • {{ value, datetime }}

Helper options use key=value pairs, for example {{ amount, currency, currency=EUR }} or {{ createdAt, datetime, timeZone=UTC, timeStyle=short }}.

Custom Formatters

Applications can register their own interpolation helpers for domain-specific formatting.

import { registerInternationalizationFormatter } from "@xtaskjs/internationalization";

registerInternationalizationFormatter("uppercase", ({ value }) => {
  return String(value).toUpperCase();
});

registerInternationalizationFormatter("relativeTime", ({ value, locale, options }) => {
  return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(
    Number(value),
    options.unit || "day"
  );
});

registerInternationalizationLocale({
  locale: "en-US",
  translations: {
    activity: {
      summary: "{{name, uppercase}} was active {{daysAgo, relativeTime, unit=day}}",
    },
  },
});

Pluralization

Plural messages can use CLDR categories and exact-count keys.

registerInternationalizationLocale({
  locale: "en-US",
  translations: {
    cart: {
      items: {
        "=0": "Your cart is empty",
        one: "{{count}} item",
        other: "{{count}} items",
      },
    },
  },
});

intl.t("cart.items", { count: 0 });
intl.t("cart.items", { count: 1 });
intl.t("cart.items", { count: 3 });

Namespace Loading

Use namespaces when translations should be split by feature and loaded lazily.

import { registerInternationalizationNamespaceLoader } from "@xtaskjs/internationalization";

registerInternationalizationNamespaceLoader("checkout", async ({ locale }) => {
  const module = await import(`./i18n/${locale}/checkout`);
  return module.default;
});

await intl.loadNamespace("checkout");
await intl.tAsync("checkout:summary.total", { count: 2 });

Custom Locale Resolution

The package ships with built-in request resolution from locale/lang query parameters, x-locale, content-language, and accept-language headers. You can extend that with custom resolvers.

import { registerInternationalizationLocaleResolver } from "@xtaskjs/internationalization";

registerInternationalizationLocaleResolver(({ request, container }) => {
  if (!request?.tenantId || !container) {
    return undefined;
  }

  return container.getByName(`tenant-locale:${request.tenantId}`);
});

Lifecycle Behavior

  • During CreateApplication(): the package initializes before container lifecycle listeners are resolved.
  • During app.close(): request context support is shut down before the DI container is destroyed.

Resources