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 🙏

© 2024 – Pkg Stats / Ryan Hefner

locator-lang

v0.2.2

Published

Language bundles compiler for locator

Downloads

23

Readme

locator-lang

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

Installation

Install using npm:

$ npm install locator-lang

Usage

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.

License

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

Contribute

See the CONTRIBUTING file for info.