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

t9n

v1.0.1

Published

Translation

Readme

t9n

Simple translation library.

Instalation

npm install t9n

Usage

1. Simple Usage

Prepare messages.json file

{
  "en": {
    "hello": "Hello"
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Translate Key
console.log(t9n.translate('hello')); // Hello

You can also set messages via constructor : new T9N({ messages: require('./messages.json') You can also set messages for a specific locale via the setLocaleMessages method : new T9N().setLocaleMessage('en', require('./en.json')


2. Nested Key

Prepare messages.json file

{
  "en": {
    "action": {
      "save": "Save",
      "cancel": "Cancel"
    }
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Translate
console.log(t9n.translate('action.save')); // Save
console.log(t9n.translate('action.cancel')); // Cancel

3. Interpolate Key

Prepare messages.json file

{
  "en": {
    "prompt": "Hi {name}, i am {me}"
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Translate
console.log(
  t9n.translate('prompt', {
    name: 'Jhon',
    me: 'Deff',
  })
); // Hi Jhon, i am Deff

4. Change Locale

Prepare messages.json file

{
  "en": {
    "hello": "Hello"
  },
  "id": {
    "hello": "Halo gan"
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Set Locale
t9n.setLocale('id');

// Translate Key
console.log(t9n.translate('hello')); // Halo gan

5. Override Default Locale

Prepare messages.json file

{
  "en": {
    "hello": "Hello"
  },
  "id": {
    "hello": "Halo gan"
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Translate Key
console.log(t9n.translate('hello'), {}, { locale: 'id' }); // Halo gan

6. Fallback Locale

Prepare messages.json file

{
  "en": {
    "hello": "Hello",
    "greet": "Good Morning"
  },
  "id": {
    "hello": "Halo gan"
  }
}

Use it in index.js

const T9N = require('t9n');

const t9n = new T9N();

// Add Messages
t9n.setMessages(require('./messages.json'));

// Set Locale
t9n.setLocale('id');

// Set Fallback Locale (default en)
t9n.setFallbackLocale('en');

// Translate Key
console.log(t9n.translate('hello')); // Halo gan
console.log(t9n.translate('greet')); // Good Morning

API

new T9N(options)

  • Return : Object - T9N instance
  • Params
    • options : Object (optional)
      • options.messages : Object (message list)
      • options.locale : String (set locale, default en)
      • options.fallbackLocale : String (set fallback locale, default en)

getMessages

  • Return : Object - message list

setMessages

  • Params
    • messages : Object (set message list, required)

getLocaleMessages

  • Return : Object - locale message list

setLocaleMessages

  • Params
    • locale : String (locale name, required)
      • messages : Object (set message list, required)

getLocale

  • Return String - Current Locale

setLocale

  • Params
    • locale : String (set locale, required)

getFallbackLocale

  • Return String - Current Fallback Locale

setFallbackLocale

  • Params
    • fallbackLocale : String (set fallback locale, required)

translate

  • Return String - Translated key
  • Params
    • key : String (required)
    • interpolateValues : Object (optional)
    • options : Object
      • locale : String (Override Current Locale)