Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

l10n-translator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

l10n-translator

Simple module for storing and retrieving l10n catalogs

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

FAQs

Package last updated on 19 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc