Language bundles compiler for locator
Last updated 6 years ago by caridy .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install locator-lang 
SYNC missed versions from official npm registry.


Language bundle compiler for Locator.

When you plug the locator-lang plugin instance into the locator instance, locator will identify any lang/*.js, lang/*.json, or lang/*.json5 files as language bundles, and provision them as locator bundle objects.

This plugin also supports the compilation of language bundles into formats that can be delivered to the client. Currently, the only supported format is the YUI module format, but we plan to add more output formats (e.g., amd, es6, etc) in the future.

Build Status


Install using npm:

$ npm install locator-lang


The examples below show how to use the plugin with locator.

Compiling language bundles

var Locator = require('locator'),
    LocatorLang = require('locator-lang'),
    loc = new Locator();

// using locator-lang plugin
loc.plug(new LocatorLang());

This example compiles any lang file into memory and exposes it through loc.getBundle('<bundleName>').lang['<lang>']['<langBundleName>'].

  • bundleName is the name that locator assigns to every bundle based on the npm package name
  • lang is the language tag (e.g., en-US)
  • langBundleName is derived from the file name from where the language entries were extracted.

Configuration Options

There are few configuration arguments that can be passed when creating a plugin instance. Here is an example:

var Locator = require('locator'),
    LocatorLang = require('locator-lang'),
    loc = new Locator({ buildDirectory: 'build' });

// using locator-lang plugin
loc.plug(new LocatorLang({
	format: 'yui',
	defaultLang: 'en',
    transpiler: 'yrb',
    requiredLangs: ['en', 'es', 'fr']

transpiler configuration

As today, only one transpiler called yrb is supported, by default it will apply a simple JSON.parse.

YRB pattern strings are externalized into resource bundles and localized by translators, while the arguments and locale are provided by the software at runtime. The use of patterns enables localization in meaningful translation units (at least complete sentences) with reordering of arguments and omission of arguments that are not relevant to some languages.

This transpiler relies on intl-messageformat to parse YRB pattern strings into JavaScript that can be used to create language resource bundles which are ultimately used to fill localized templates.

format configuration

The only format supported as today is yui. In this example above, each language bundle will be compiled into files containing YUI modules under the build folder.

defaultLang configuration

This value defines what language to use when a lang bundle source file does not include the locale as part of the filename. In this example above, for a file like path/lang/foo.json, a new file will be generated as foo_en.js.

requiredLangs configuration

The requiredLangs configuration specifies an array of required languags. If this value is set, the plugin will complete language bundles and/or entries based on the defaultLang. In other words, if you haven't done the translation for a particular language, the plugin will fallback to the default language bundle by using the default values as the values for the missing language. The same happen for individual entries in each language bundle, and the plugin will be able to analyze each file, and fallback to a default entry/message when it is missing in a particular language bundle. This guarantee that your application can assume all entries/messages and lang bundles are in place for all the languages in the requiredLangs configuration.


This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.


See the CONTRIBUTING file for info.

Current Tags

  • 0.2.2                                ...           latest (6 years ago)

11 Versions

  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
  • 0.0.1-rc2                                ...           7 years ago
  • 0.0.1-rc                                ...           7 years ago
  • 0.0.1-beta                                ...           7 years ago
  • 0.0.1-alfa                                ...           7 years ago
Maintainers (2)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (7)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |