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

l10n-translator

v1.1.0

Published

Simple module for storing and retrieving l10n catalogs

Downloads

7

Readme

Translator

A simple module for loading l10n catalogs and retrieving verbiage from them. Work in progress, fits my current usage case better than some of the other modules available. Likely not production ready until I implement the ability to specify a path.

Build Status

Build Status

Installation

If you're a Node user, Translator is available on npm:

$ npm install l10n-translator

If you're interested, you can also:

npm test

or

make test

To verify things are still wired up correctly.

Usage

Using Translator is relatively simple, currently only set up for usage as a require module. Out of the box looks like this:

var Translator = require('l10n-translator'),
    catalog = new Translator('relative/project/path');

term = catalog.lookup('PROPERTY_NAME');
// -> { code: 'PROPERTY_NAME', locale: 'en_us', value: null }

You can specify the default/fallback locale by:

var catalog = new Translator('relative/project/path','en_fr');

or by changing it:

catalog.setLocale('en_fr');

or at will:

catalog.lookup('PROPERTY_NAME', req.user.locale)

Catalog Files

Catalog locale files should be placed in the folder you provide when creating a new Translator. They should end in .js, be named simple things like en_us or en_fr, and be formatted something like this:

"locale/en_us.js"
// l10n `en_us`
var defs = module.exports = {};

// constants style
defs.SIGNIN_FAILED = "You couldn't sign in. Error Code: #104";
defs.SUBMIT_BUTTON = "Submit";
defs.SIGN_OUT_ACTION = "Log out";

Behavior

Loads all *.js files in a relative directory and attaches them to the translator.catalog. In the future locales will be able to be specified. The default locale is currently en_us.

If you attempt to lookup a value from a catalog (en_fr) that does not exist or is not loaded, Translator will try to return the value from the default catalog.

var term = catalog.lookup('known_value', 'loaded_catalog');
// -> { code: 'known_value', locale: 'loaded_catalog', value: VALUE }

var term = catalog.lookup('known_value', 'null_catalog');
// -> { code: 'known_value', locale: 'default_catalog', value: VALUE }

This allows you to decide to ignore the result and pass it through, or strictly enforce only showing it if the locale matches your desired input locale. Value is returned as null when no results were able to be found.

Changelog

1.1.0

  • Terms returned now return term.value when cast as a String (as opposed to [object Object])

1.0.1

  • Updated README
  • Added Makefile for tests

1.0.0

  • Breaking API changes: New feature allows catalog directory (relative to process.cwd()) to be provided) -- Is actually required more than "allowed"
  • Syntax Style updates
  • Fixed minor logic in default catalog behavior
  • More unit tests
  • Ghost implementation of allowing catalog languages to be specified (expect functionality in future release)

0.0.2

  • Initial release
  • Not very useful
  • Shipped quickly and had unit tests!