How to use the node-polyglot.prototype function in node-polyglot

To help you get started, we’ve selected a few node-polyglot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashlkv / sapsanasap / polyglot.js View on Github external
const Polyglot = require('node-polyglot');
const _ = require('lodash');
// TODO Determine locale
// TODO Per-user locale, not per-instance locale
const locale = process.env.LOCALE || 'en';

const moment = require('moment');
moment.locale(locale);

const SapsanPolyglot = function() {
	Polyglot.call(this);
};

SapsanPolyglot.prototype = Object.create(Polyglot.prototype);

// Extending polyglot extend method to allow non-string values (e.g. regexps and functions)
SapsanPolyglot.prototype.extend = function(morePhrases, prefix) {
	_.forEach(morePhrases, function(phrase, key) {
		var prefixedKey = prefix ? prefix + '.' + key : key;
		this.phrases[prefixedKey] = phrase;
	}.bind(this));
};

// Extending polyglot translate method to allow non-string values (e.g. regexps and functions)
SapsanPolyglot.prototype.t = function(key, options) {
	var phrase = this.phrases[key];
	var result;
	if (typeof phrase === 'function' || typeof phrase === 'object' ||  _.isRegExp(phrase)) {
		result = phrase
	} else  {
github ashlkv / sapsanasap / polyglot.js View on Github external
SapsanPolyglot.prototype.t = function(key, options) {
	var phrase = this.phrases[key];
	var result;
	if (typeof phrase === 'function' || typeof phrase === 'object' ||  _.isRegExp(phrase)) {
		result = phrase
	} else  {
		result = Polyglot.prototype.t.call(this, key, options);
	}
	return result;
};

node-polyglot

Give your JavaScript the ability to speak many languages.

BSD-2-Clause
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis