0.0.1 • Published 8 years ago

ti18ny v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

i18ny (WIP) build

Tiny, minimalistic, extensible internationalization library.

Existing i18n libraries are bloated. This one is ti18ny. You can use it as-is or extend it with the features you need.

This is still work in progress, breaking changes are likely to happen.

Basic Functionality

  • keeping a dictionary of values ✓
  • easy access to values of the dictionary using '.' notation ✓
  • Interpolating placeholders ✓

Advanced Functionality

  • loading a dictionary of values from storage (at initialization)
  • dynamically loading a dictionary
  • reporting missing/untranslated keys

Features

  • Tiny. 1k.
  • Plugins for Handlebars, lodash

API

i18n(options) : t

const i18n = require('i18n');

const t = i18n({
  en: {
    hello: 'hello, { first_name }!'
  },
  de: {
    hello: 'Hallo, { first_name }!'
  }
});

const person = {
  first_name: 'Andreas'
};

t( 'en.hello', person ); // "hello, Andreas!"
t( 'de.hello', person ); // "Hallo, Andreas!"
const i18n = require('i18n');
const resources = require('./en_US.json');
const t = i18n(resources);

t('hello', person); // // "hello, Andreas!"

options

  • fallbackLocale
  • get
  • compileTemplate
  • executeTemplate

t(key : string, data : object) : string

t.for( prefix : string ) : t

Plugins

Plugins are node modules.

const i18n =
  require('i18n')
  .use(myPlugin);