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

oftn-l10n

v0.2.1

Published

Android-style localization for ES6

Downloads

22

Readme

oftn-l10n

oftn-l10n is a simple and straight-forward JavaScript library that enables localization through Android-style property accesses. Pair your accesses with the special comment syntax in order to define a default value. That way, it can simply be extracted from source with webpack-extract-oftn-l10n and a base localization file can be automatically created. Don't duplicate effort!

If available, it is best used with the EcmaScript Internationalization API.

Getting started

The first step is getting the user's current language. This can be done several ways. See oftn-l10n-example to view a more detailed example using this library.

Node.js

// You can use a package like os-locale to get the system locale.
const oslocale = require('os-locale');
// Convert from ISO 15897 format to IETF language tag
// Examples: en, en-US, es, zh, ru
const language_tag = oslocale.sync().replace(/_/g, '-');

Browser / Electron Renderer

// Get the current locale with the navigator object
const language_tag = navigator && (navigator.language || navigator.userLanguage) || "";

Usage

Example with proxying

// Include the library
const l10n = require('oftn-l10n');

const R = l10n.proxy({
  // Location of root localizations object
  path: './localizations.json',
  lang: language_tag
});

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

console.log(R.welcome); // R.welcome = "Hello and welcome!"

// R.get_name = "Before we get started, what is your name, good sir? "
rl.question(R.get_name, (answer) => {
  // R.thank_you = "Very nice, {0}."
  console.log(l10n.format(R.thank_you, answer));
  // R.goodbye = "Have a wonderful day, goodbye!"
  console.log(R.goodbye);

  rl.close();
});

And of course, after generating the referenced localizations.json, the output is as expected:

Hello and welcome!
Before we get started, what is your name, good sir? None of your business
Very nice, None of your business.
Have a wonderful day, goodbye!

Without proxying

// Make convenience function
const _ = (() => {
  const strings = new l10n.Localizer({
    path: path.resolve(__dirname, 'localizations/all.json'),
    lang: 'es-MX'
  });
  return (name) => {
    return strings.get(name);
  }
})();

// _.welcome = "Hello, world!"
console.log(_('welcome'));

String extraction

A working plugin for Webpack 2 is available called webpack-extract-oftn-l10n. Use it to generate your base localization files automatically.

It looks at every comment looking for <identifier>.<property> = <string>. If the identifier matches the one configured, it adds it to the list of translatable strings. Save the file as default.json. A Russian translator can create a new translation by copying this file to ru.json and changing the language tag from "" to "ru".

The localization file and best practices

type LanguageTag = string; // IETF language tag or "" for defaults
type LanguageReference = string; // Relative path to localization file to include

interface LanguageDictionary {
    [name: string]: string | undefined;
}

interface Localization {
  [tag: LanguageTag]: LanguageReference | LanguageDictionary | undefined;
}

You may split up your localizations into multiple files for translators using a link. Linked files are loaded on-demand when necessary.

localizations/all.json

{
    "": "default.json",
    "bg": "bg.json",
    "ca": "ca.json",
    "cs": "cs.json",
    "da": "da.json",
    "de": "de.json",
    "en": "en.json",
    "es": "es.json",
    "fi": "fi.json",
    "fr": "fr.json",
    "he": "he.json",
    "hu": "hu.json",
    "it": "it.json",
    "ja": "ja.json",
    "jbo": "jbo.json",
    "la": "la.json",
    "nb": "nb.json",
    "nl": "nl.json",
    "no": "no.json",
    "pl": "pl.json",
    "pt": "pt.json",
    "ru": "ru.json",
    "se": "se.json",
    "tr": "tr.json",
    "vi": "vi.json",
    "zh": "zh.json"
}

localizations/default.json (automatically generated)

{
  "": {
    "app_name": "App.io",
    "welcome": "Welcome to {0}!",
    "localizations": "Localizations"
  }
}

localizations/en.json

{
  "en-UK": {
    "localizations": "Localisations"
  }
}

localizations/es.json

{
  "es": {
    "welcome": "Bienvenidos a {0}!",
    "localizations": "Localizaciónes"
  }
}