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

intl-template

v1.0.7

Published

l10n tagged template literals

Downloads

251

Readme

intl-template

A tiny i18n/l10n helper built on JavaScript Tagged Template Literals.

intl-template lets source strings stay close to your UI code while translations live in a simple locale-indexed template map.

Installation

npm install intl-template

Quick Start

import translation, { l10n } from "intl-template"

translation.locale = "es-ES"
translation.templates["es-ES"] = {
    "hello {}": "hola {}",
}

const name = "Willow"

console.log(l10n`hello ${name}`.toString())
// => hola Willow

Every interpolation in a tagged template becomes {} in the translation key. For example, l10nhello ${name}`` looks up the key "hello {}".

By default, translations return a Runes array so React nodes and other non-string values can pass through unchanged. Call .toString() when you need plain text, or create a Translation instance in "string" mode.

Templates

translation.templates["en-US"] = {
    "hello {}": "hello {}",
    "{} invited {}": "{} invited {}",
}

translation.templates["de-DE"] = {
    "hello {}": "hallo {}",
    "{} invited {}": "{1} wurde von {0} eingeladen",
}

Use {} to keep the original slot order. Use {0}, {1}, and later indexes when a locale needs a different order.

Locale

The shared translation instance uses navigator.language when it is available, then falls back to "en". You can also set the locale explicitly.

import translation, { l10n } from "intl-template"

const browserLocale = navigator.language

translation.locale = browserLocale
translation.templates[browserLocale] = {
    "hello {}": "hola {}",
}

console.log(l10n`hello ${"Willow"}`.toString())
// => hola Willow

Examples

React

The default "react" mode keeps interpolated values as values, so JSX can be used inside a translation.

import translation, { l10n } from "intl-template"

translation.locale = "es-ES"
translation.templates["es-ES"] = {
    "hello {}": "hola {}",
}

function Greeting({ name }) {
    return (
        <p>
            {l10n`hello ${<strong key="name">{name}</strong>}`}
        </p>
    )
}

Slot Order

translation.locale = "de-DE"
translation.templates["de-DE"] = {
    "{} invited {}": "{1} wurde von {0} eingeladen",
}

const inviter = "Willow"
const guest = "Jack"

console.log(l10n`${inviter} invited ${guest}`.toString())
// => Jack wurde von Willow eingeladen

Nested Translations

translation.locale = "de-DE"
translation.templates["de-DE"] = {
    "Bill": "Schmidt",
    "hello {}": "hallo {}",
}

console.log(l10n`hello ${l10n`Bill`}`.toString())
// => hallo Schmidt

Function Slots

When a slot is a function, it receives the active locale.

translation.locale = "de-DE"
translation.templates["de-DE"] = {
    "current locale: {}": "aktuelle Sprache: {}",
}

console.log(l10n`current locale: ${locale => locale}`.toString())
// => aktuelle Sprache: de-DE

Call as a Function

Tagged templates and function calls use the same placeholder format.

translation.locale = "es-ES"
translation.templates["es-ES"] = {
    "hello {}": "hola {}",
}

console.log(l10n("hello {}", "Willow").toString())
// => hola Willow

String Mode

import { Translation } from "intl-template"

const translation = new Translation("es-ES", "string")

translation.templates["es-ES"] = {
    "hello {}": "hola {}",
}

const t = translation.translate

console.log(t`hello ${"Willow"}`)
// => hola Willow

API

translation

The default shared Translation instance.

l10n

A shorthand for translation.translate.

new Translation(defaultLocale, mode)

Creates an isolated translation instance.

  • defaultLocale: locale used by this instance.
  • mode: "react" by default, or "string" for plain string output.

translation.locale

The active locale used by translate.

translation.templates

Locale-indexed translation templates.

translation.templates["es-ES"] = {
    "source {}": "translated {}",
}

translation.translate(strings, ...parts)

Translates a tagged template or a string with {} placeholders.