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

i10n-language-builder

v0.0.4

Published

Library for generating internationalized language files for multiple regions

Downloads

10

Readme

i10n-language-builder

NPM version Build status Coverage Status Dependency Status

Command line utility for building internationalized JSON-based language files across multiple regions.

Installation

Install from NPM:

npm install i10n-language-builder

How It Works

Now that your application has hit it big, you'd like to translate it into multiple languages. JSON seems like a good format to use since it's easy to traverse in JavaScript and has good support for nesting and grouping related terms together using objects. Also, Format.js and i18next are pretty cool, as is the ICU Message Syntax.

Base Language Files

You'll start with your base language files. These should be named using the two character primary language subtag (ISO 639-1). For example: en.json (English), es.json (Spanish), fr.json (French).

Sample English (en.json):

{
	"Intro": "Welcome to harbor center",
	"Opening": "It's where ships seek shelter from stormy weather"
}

Any English speakers using your application from outside the United States will quickly point out that "center" is spelled "centre" and "harbor" is actually "harbour". To solve this, we need some regional overrides...

Regional Language Files

For each language, there might be zero or more regional overrides to handle region-specific changes. These files should be prefixed with the language subtag of the base language, followed by a hyphen, followed by a two character regional subtag. For example: en-CA.json (Canadian English), en-GB.json (United Kingdom English), en-AU.json (Australian English), and so on.

Sample Canadian English (en-CA.json):

{
	"Intro": "Welcome to harbour centre"
}

These region-specific files only need to override the terms that differ from the base language. They can also be empty.

Putting it all together

When you point i10n-language-builder at a directory containing your base and regional language files, it will produce a set of files that contains the union of each base file with each regional override file. This is most useful as a step in your application's build process.

Other features:

  • If your translations for some languages aren't ready yet, you can provide a default language as a fallback
  • If a region file exists (e.g. fr-CA.json) but there's no base file (e.g. fr.json), an error occurs
  • If a region file overrides a term that does not exist in the base file, an error occurs
  • If the data type in a region file differs from that in the base file, an error occurs

Usage from the command line

i10n-language-builder <path> <output> --fallback=fr

Where:

  • path: directory containing base and region language files
  • output: directory to place output files
  • fallback: language to use when translations are missing

Programmatic usage

You can also use i10n-language-builder from your JavaScript application:

var langBuilder = require('i10n-language-builder');

var opts = {
	input: 'inputDir',
	output: 'outputDir',
	fallback: 'fr' // defaults to "en"
};
langBuilder(opts, function(err) {
	// callback when processing is complete
});

Contributing

Contributions are welcome, please submit a pull request!

Code Style

This repository is configured with EditorConfig rules and contributions should make use of them.