🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

z-trans

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z-trans

A simple translator that works similar to the Symfony Translator Component.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

trans.js

Build Status npm version

This is a simple translation solution, which is inspired by the Symfony Translator Component.

It's a CommonJS module, so it must be used alongside with Browserify, or something similar, like WebPacker.

Example

// Requiring the module
var translator = require('z-trans');

// Adding the translation data. This could come from anywhere like: Ajax, jsonp,
// another module or the parsed JSON contents of a DOM element.
translator.addData('en', {
    domain_name: {
        translation_key: '(en) translation_value: "%parameter%"',
        translation_key2: 'something still not translated to the "hu" locale',
    }
});
translator.addData('hu', {
    domain_name: {
        translation_key: '(hu) translation_value: "%parameter%"'
    }
});

// Domains could be added later on if needed.
translator.addDomainData(
    'en',
    'another_domain_name',
    {
        some_key: 'some value'
    }
);

// If a translation fails in the current locale, it will fall back to the
// default locale
translator.defaultLocale = 'en';
translator.locale = 'en';

// Returns '(en) translation_value: "param"'
console.log(translator.trans('translation_key', {'%parameter%': 'param'}, 'domain_name'));

// Returns 'some value'
console.log(translator.trans('some_key', null, 'another_domain_name'));

// Returns 'something still not translated to the "hu" locale'
console.log(translator.trans('translation_key2', null, 'domain_name', 'hu'));

License

MIT

FAQs

Package last updated on 07 Jun 2015

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