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

@rudderjs/localization

v0.0.7

Published

Laravel-style localization for RudderJS. JSON translation files, named interpolation, pluralization, and per-request locale via AsyncLocalStorage.

Readme

@rudderjs/localization

Laravel-style localization for RudderJS. JSON translation files, named interpolation, pluralization, and per-request locale via AsyncLocalStorage.

pnpm add @rudderjs/localization

Setup

1. Create lang files

lang/
  en/
    messages.json
  es/
    messages.json
{
  "welcome": "Welcome to :app!",
  "greeting": "Hello, :name!",
  "items": "{0} no items|{1} one item|{n} :count items"
}

2. Add config

// config/localization.ts
import { resolve } from 'node:path'

export default {
  locale: 'en',
  fallback: 'en',
  path: resolve(import.meta.dirname, '../lang'),
}

3. Register provider

// bootstrap/providers.ts
import { localization } from '@rudderjs/localization'
import configs from '../config/index.js'

export default [
  localization(configs.localization),
]

Usage

__() - synchronous (cache only)

import { __ } from '@rudderjs/localization'

__('messages.welcome', { app: 'RudderJS' }) // 'Welcome to RudderJS!'
__('messages.items', 3) // '3 items'

Returns the key string if not found. Use __() when the namespace is already loaded.

trans() - async (loads from disk)

import { trans } from '@rudderjs/localization'

await trans('messages.greeting', { name: 'Alice' }) // 'Hello, Alice!'
await trans('messages.items', 0) // 'no items'

Loads the namespace JSON from disk on first call, then caches in memory.

Vike / SSR note: Always use trans() (not __()) in Vike +data.ts files. The registry config and translation cache are stored on globalThis so they survive Vike's SSR module isolation. __() is safe inside middleware and request handlers that run after the namespace is already loaded.


Pluralization

Use pipe-separated forms in JSON values:

{ "apples": "{0} no apples|{1} one apple|{n} :count apples" }
await trans('messages.apples', 0) // 'no apples'
await trans('messages.apples', 1) // 'one apple'
await trans('messages.apples', 12) // '12 apples'

Simple two-part form also works:

{ "item": "one item|many items" }
await trans('messages.item', 1) // 'one item'
await trans('messages.item', 5) // 'many items'

Locale switching

import { getLocale, setLocale, LocalizationMiddleware } from '@rudderjs/localization'

getLocale() // 'en'
setLocale('es')
LocalizationMiddleware()

setLocale() only works inside a request context (within runWithLocale()).


Nested keys

{
  "nav": {
    "home": "Home",
    "profile": "My Profile"
  }
}
__('messages.nav.home') // 'Home'
__('messages.nav.profile') // 'My Profile'

Fallback locale

If a key is missing in the current locale, resolution automatically falls back to the configured fallback locale.