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

@dws-std/i18n

v1.2.0

Published

Type-safe i18n for TypeScript — define localized exception and message catalogs with compile-time validated parameters.

Downloads

290

Readme

🌐 DWS I18n

Type-safe internationalization for TypeScript. Define your translation catalogs once, and get localized messages and HTTP exceptions with full traceability, all validated at compile time.

Why this package?

Internationalization is often treated as an afterthought, strings scattered across files, parameters interpolated by hand, no type safety.
This package takes a different approach: you declare structured catalogs with entry(), and the compiler does the rest.
Parameters, locales, HTTP statuses, if something's wrong, you'll know before your code even runs.

It also plays nicely with @dws-std/error. Exception catalogs produce LocalizedHttpException instances that carry translations, a UUID v7, and an HTTP status code, so your error handling stays consistent and traceable.

📌 Table of Contents

✨ Features

  • 🔒 Type-safe catalogs : Parameters, locales, and HTTP status are all validated at compile time thanks to entry().
  • 🌍 Multi-locale : Each entry holds all its translations; pick the right one at call-time.
  • 🚨 Localized exceptions : defineExceptionCatalog gives you factory functions that create LocalizedHttpException instances, complete with status codes and UUID tracking.
  • 💬 Localized messages : defineMessageCatalog does the same for plain messages : confirmations, notifications, anything that isn't an error.
  • 🔗 Template interpolation : Use {{param}} placeholders in translations; resolveMessage fills them in.
  • 🔍 UUID v7 tracking : Every exception inherits traceability from @dws-std/error.

🔧 Installation

bun add @dws-std/i18n

Peer dependency: @dws-std/error must be installed alongside.

⚙️ Usage

Defining entries

entry() is the building block. Give it a status and it becomes an exception entry; leave status out and it's a plain message entry.

import { entry } from '@dws-std/i18n';

// This will produce a LocalizedHttpException when used in an exception catalog
const unauthorized = entry({
	status: 'UNAUTHORIZED',
	translations: {
		en: 'Invalid credentials',
		fr: 'Identifiants invalides'
	}
});

// This will produce a plain LocalizedMessage when used in a message catalog
const welcome = entry<{ name: string }>({
	translations: {
		en: 'Welcome, {{name}}!',
		fr: 'Bienvenue, {{name}} !'
	}
});

Exception catalogs

Group related exception entries under a namespace. Each key becomes a factory function you can call to throw a localized exception.

import { defineExceptionCatalog, entry } from '@dws-std/i18n';

const AUTH_ERRORS = defineExceptionCatalog({
	namespace: 'auth',
	defaultLocale: 'en',
	definitions: {
		invalidCredentials: entry({
			status: 'UNAUTHORIZED',
			translations: {
				en: 'Invalid credentials',
				fr: 'Identifiants invalides'
			}
		}),
		emailTaken: entry<{ email: string }>({
			status: 'CONFLICT',
			translations: {
				en: 'Email "{{email}}" is already taken',
				fr: 'L\'email "{{email}}" est déjà utilisé'
			}
		})
	}
});

// Throws a LocalizedHttpException with status 401
throw AUTH_ERRORS.invalidCredentials();

// With parameters, type-checked, so you can't forget one
throw AUTH_ERRORS.emailTaken({ email: '[email protected]' });

Message catalogs

Same idea, but for things that aren't errors, success confirmations, notifications, labels, etc.

import { defineMessageCatalog, entry } from '@dws-std/i18n';

const DNS_MESSAGES = defineMessageCatalog({
	defaultLocale: 'en',
	definitions: {
		recordCreated: entry({
			translations: {
				en: 'DNS record created successfully',
				fr: 'Enregistrement DNS créé avec succès'
			}
		})
	}
});

const msg = DNS_MESSAGES.recordCreated();

Resolving to a specific locale

resolveMessage takes a LocalizedHttpException or a LocalizedMessage and returns the interpolated string for the locale you want.

import { resolveMessage } from '@dws-std/i18n';

const error = AUTH_ERRORS.emailTaken({ email: '[email protected]' });

resolveMessage(error); // default locale → "Email "[email protected]" is already taken"
resolveMessage(error, 'fr'); // → "L'email "[email protected]" est déjà utilisé"

📚 API Reference

Full docs: Dominus-Web-Service.github.io/packages

⚖️ License

MIT - Feel free to use it.

📧 Contact