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

node-i18n-core

v0.2.1

Published

node-i18n-core

Readme

Build Status Coverage Status MIT license

Simplest I18n Solution for all platforms

This may be the simplest i18n module for nodejs and the web.

Locale Directory

locales/
├── en.json
├── en-US.json
├── kr.json
└── zh-CN.json

All locale files must be kept within one directory, with file extension .json and in json format.

Usage

import

import { I18n, II18nOption, IStorable, IListener } from 'node-i18n-core';

Options

There are three options in II18nOption.

  1. current: the current locale.
  2. url: an absolute path of file system or uri.
  3. loader: an async function through which locale data is read asynchronously

Loaders

There are two Loaders, one is FileSystemLoader, the other is HTTPLoader.

As their names imply, one is for file system, the other is for web served json files.

FileSystemLoader

url should be an absolute path

  const options: II18nOption = {
    current: 'en',
    loader: FileSystemLoader,
    url: path.resolve(__dirname, './locales/'),
  };

HTTPLoader

url should be an uri path where json files are served

  const options: II18nOption = {
    current: 'en',
    loader: HTTPLoader,
    url: 'http://www.yourdomain.com/xxx/locales/'
  };

Create I18n Instance

You can specify your storage or not.

const i18n = new I18n(options);

// Use windows.localStorage as the IStorable interface on the web
const i18n = new I18n(options, windows.localStorage);

Init data

To use translator, data must be initialized at first:

await i18n.init();

Now you have the json data prepared for access.

Get Locale

// Get Locale loaded from windows.localStorage
i18n.getLocale();

Define Customzied IStorable object


// Define an IStorable for yourself
const storage: IStorable = {
    getItem: (key: string): string => {
      return data[key];
    },
    setItem: (key: string, value: string): void => {
      data[key] = value;
    }
};

// Get Locale from a customzied IStorable instance
i18n.getLocale(storage);

Set Locale (Async)

// Set Locale to constructed storage
await i18n.setLocale('zh-CN');

// Set Locale to a temporay storage
await i18n.setLocale('zh-CN', storage);

Add Change Observer

// Listen the locale change infomation
const listener: IListener = (from, to) => {
  console.log("locale has changed from: " + from + " to :" + to );
};
i18n.listen(listener);

Get Translation (Async)

// Get translated strings async
await i18n._('TITLE');
await i18n._('TITLE.SUBTITLE.SUBTITLE');
await i18n._('TITLE', 'zh-CN');
await i18n._('TITLE.SUBTITLE.SUBTITLE', 'ja');

// Get translated strings, no await need, return '' if not loaded or error.
 i18n._sync('TITLE');
 i18n._sync('TITLE.SUBTITLE.SUBTITLE');
 i18n._sync('TITLE', 'zh-CN');
 i18n._sync('TITLE.SUBTITLE.SUBTITLE', 'ja');