anytv-i18n
A module for globalization
Last updated 3 years ago by anytv_npmjs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install anytv-i18n 
SYNC missed versions from official npm registry.

anytv-i18n

A module for app internationalization

Install

npm install anytv-i18n@latest --save

Introduction

Simple example:

'use strict';

const i18n = require('anytv-18n');

i18n.configure({
    languages_url: 'http://translations.myapp.com/:project/languages',
    translations_url: 'http://translations.myapp.com/:project/:lang.json',
    locales_dir: '_locales',
    default: 'en',
    debug: true
});

i18n.use('freedom_dashboard')
    .load()
    .then(() => {

    	// function to call when everything is loaded
        i18n.trans('zh_TW', 'greetings', {
            name: 'Raven!'
        });

        i18n.trans('non_existent_key'); // empty string
    })
    .catch(() => {
        // function to call when there's an error
    });



Configuration options

  • languages_url url for getting all available languages in json. :project will be replaced by the project you're using. Exact JSON format:
{
	"data": {
		"languages": [
			"en",
			"zh",
			"zh_TW"
		]
	}
}
  • translation_url url for getting json translations. :project will be replaced by the project you're using. :lang will be replaced by the language you're using. Exact format:
{
	"greetings": "你好 :name",
	...
}
  • locale_dir directory where the translations will be cached. should be an absolute path with a trailing backslach. example: /home/user/my-app/_locales/
  • debug set to true if you want to debug
  • logger replaces the default logger

    note: Only Winston-like loggers are accepted

Todo

  • [ ] Add test cases

Contributing

Install the tools needed:

npm install grunt -g
npm install --dev

To compile the ES6 source code to ES5:

grunt

To generate the docs:

esdoc -c ./esdoc.json

Running test

npm test

Code coverage

npm run coverage

Then open coverage/lcov-report/index.html.

License

MIT

Author

Freedom! Labs, any.TV Limited DBA Freedom!

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

9 Versions

  • 2.0.0                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 3
Dependencies (4)
Dev Dependencies (12)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |