ez-localize
Super-simple localization of strings in a Node/Browserify application
Last updated 2 months ago by grassick .
LGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ez-localize 
SYNC missed versions from official npm registry.

ez-localize

Localizing an application should be easy, not hard. ez-localize makes it ridiculously simple.

Usage

Step 1: Use T() to wrap strings

Just replace:

console.log("Hello world!");

With:

console.log(T("Hello world!"));

Step 2: Extract strings from your application

var extractor = require('ez-localize/extractor');

extractor.updateLocalizationFile("index.js", "localizations.json", {}, function() { console.log("done!")})

Step 3: Create a localizer and make global

var ezlocalize = require('ez-localize');
var localizations = require('localizations.json');

var localizer = new ezlocalize.Localizer(localizations, "en")
localizer.makeGlobal();

Step 4: Edit localizations.json to add other languages and translations

You're done!

Advanced

String substitution:

console.log(T("This works {0}%!", 100);

React-style substitution:

console.log(T("This works {0}%!", { x: 10 });

will create array of ["This works ", { x: 10 }, "%!"]

It handles Coffeescript and Handlebars too:

var options = { extensions: ['.js', '.coffee'], transform: [coffeeify, hbsfy] };
extractor.updateLocalizationsupdateLocalizationFile("index.js", "localizations.json", options, function() { console.log("done!")})

To register a T helper:

var ezlocalize = require('ez-localize');
var handlebars = require("hbsfy/runtime");
var localizations = require('localizations.json');

var localizer = new ezlocalize.Localizer(localizations, "en")
localizer.makeGlobal(handlebars);

Only relative requires are included by default. To include another module, pass externalModules to options, an optional list of external modules to include

Localizing a JSON object

To localize the strings inside a JSON object (plain javascript object), use require('ez-localize/lib/JsonLocalizer`)

Current Tags

  • 2.0.4                                ...           latest (2 months ago)

42 Versions

  • 2.0.4                                ...           2 months ago
  • 2.0.3                                ...           7 months ago
  • 2.0.2                                ...           7 months ago
  • 2.0.1                                ...           7 months ago
  • 2.0.0                                ...           7 months ago
  • 1.3.1                                ...           7 months ago
  • 1.3.0                                ...           7 months ago
  • 1.2.0                                ...           8 months ago
  • 1.1.1                                ...           8 months ago
  • 1.1.0                                ...           8 months ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.6                                ...           3 years ago
  • 0.6.5                                ...           4 years ago
  • 0.6.4                                ...           4 years ago
  • 0.6.3                                ...           4 years ago
  • 0.6.2                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.3                                ...           4 years ago
  • 0.4.2                                ...           5 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.7                                ...           5 years ago
  • 0.3.6                                ...           5 years ago
  • 0.3.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.2.8                                ...           5 years ago
  • 0.2.7                                ...           5 years ago
  • 0.2.6                                ...           5 years ago
  • 0.2.5                                ...           5 years ago
  • 0.2.4                                ...           5 years ago
  • 0.2.3                                ...           5 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 84
Dependencies (14)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |