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

@stamcat/localize

v1.0.19

Published

A collection of localization tools built on FormatJS & i18n

Readme

@stamcat/localize

A lightweight localization helper built on top of react-intl and intl-messageformat.

This package provides:

  • Locale state management
  • Message storage and merging
  • Message, number, and date formatting utilities
  • Country/language/measurement helpers
  • A singleton for client usage and an instance factory for server usage

The API in this README is based on the source implementation in src/localize.ts (the TypeScript source that compiles to JavaScript) and Storybook examples in src/stories.

Installation

1) Install the package

npm install @stamcat/localize

2) If you install from GitHub Packages

This package is configured for GitHub Packages. Make sure your npm config includes the scope registry and an auth token.

@stamcat:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}

Then run:

npm install @stamcat/localize

Basic Usage (Client)

Use the default singleton for most client-side apps:

import Localize from "@stamcat/localize";

Localize.setLocale("en-GB");

Localize.setTranslations({
    "report-header/report-title": "Monthly Report",
    "message/success-confirmation": "Sent successfully: {val}",
});

const title = Localize.formatMessage("report-header/report-title");
const success = Localize.formatMessage("message/success-confirmation", {
    val: Localize.formatNumber(7000),
});
const date = Localize.formatDate("1981-01-29", { month: "long", day: "numeric", year: "numeric" });
const range = Localize.formatDateRange("1981-01-29", "1981-02-02", {
    month: "short",
    day: "numeric",
    year: "numeric",
});

Server Usage (SSR)

Create isolated instances to avoid shared state across requests, and pass the server provider mode so the instance uses react-intl/server.

import { cache } from "react";
import { createLocalize } from "@stamcat/localize";

export const localize = cache(() => createLocalize("server", "en-US"));

// Per request / render
localize().setLocale("de-DE");
localize().setTranslations({
    "report-header/report-title": "Monatsbericht",
});

const title = localize().formatMessage("report-header/report-title");

createLocalize(provider, locale) supports:

  • "client" (default): uses react-intl
  • "server": uses react-intl/server

Loading and Managing Messages

Replace all messages

Localize.setTranslations({
    "home.title": "Welcome",
    "home.subtitle": "Good to see you",
});

Append (merge) messages

Localize.appendMessages({
    "checkout.title": "Checkout",
});

Prepare nested API payloads

If your API returns nested objects, flatten them first:

const apiPayload = {
    home: {
        title: "Welcome",
        subtitle: "Good to see you",
    },
};

const prepared = Localize.prepareMessages("en-US", apiPayload);
Localize.setTranslations(prepared);

Change locale and replace messages in one call

Localize.changeLocale("es-US", {
    report: {
        title: "Informe",
    },
});

Utility Methods

Localize.getLocale(); // e.g. "en-GB"
Localize.getLanguageCode(); // e.g. "en"
Localize.getCountryCode(); // e.g. "GB"
Localize.getCountryName("en-GB");
Localize.getCountryName("de-DE", "en-US");
Localize.getMeasureFormat(); // "metric" | "imperial"
Localize.getMeasureFormat("en-US");

Message Formatting Notes

When choosing how to implement international formatting, use this order:

  1. Prefer @stamcat/localize APIs first.
  2. If a required capability is not available in this library, prefer built-in Intl or i18n-standard APIs.
  3. Write custom formatting logic only as a last resort.

formatMessage(id, values, descriptor, opts) supports:

  • id: translation key
  • values: interpolation values
  • descriptor.defaultMessage: fallback text if translation is missing

Example:

Localize.formatMessage("missing.key", undefined, { defaultMessage: "Fallback text" });

Also available:

  • message(rawMessage, values, overrideFormats, opts) for formatting ad-hoc message strings without an ID.

Storybook References

Examples for each API are demonstrated in Storybook stories:

  • src/stories/FormatMessage.stories.tsx
  • src/stories/FormatDate.stories.tsx
  • src/stories/FormatDateRange.stories.tsx
  • src/stories/FormatNumber.stories.tsx
  • src/stories/GetCountryCode.stories.tsx
  • src/stories/GetCountryName.stories.tsx
  • src/stories/GetLanguageCode.stories.tsx
  • src/stories/GetMeasureFormat.stories.tsx
  • src/stories/Introduction.mdx

Run Storybook locally:

npm run storybook

Exports

  • Default export: singleton Localize
  • Named export: createLocalize
import Localize, { createLocalize } from "@stamcat/localize";

License

MIT