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

node-gettext

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gettext - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

26

lib/gettext.js

@@ -12,5 +12,8 @@ 'use strict';

* @constructor
* @param {Object} [options] A set of options
* @param {Boolean} options.debug Whether to output debug info into the
* console.
* @param {Object} [options] A set of options
* @param {String} options.sourceLocale The locale that the source code and its
* texts are written in. Translations for
* this locale is not necessary.
* @param {Boolean} options.debug Whether to output debug info into the
* console.
* @return {Object} A Gettext instance

@@ -27,2 +30,13 @@ */

// Set source locale
this.sourceLocale = '';
if (options.sourceLocale) {
if (typeof options.sourceLocale === 'string') {
this.sourceLocale = options.sourceLocale;
}
else {
this.warn('The `sourceLocale` option should be a string');
}
}
// Set debug flag

@@ -138,3 +152,3 @@ if ('debug' in options) {

if (!this.catalogs[locale]) {
if (locale !== this.sourceLocale && !this.catalogs[locale]) {
this.warn('You called setLocale() with "' + locale + '", but no translations for that locale has been added.');

@@ -312,3 +326,3 @@ }

}
else {
else if (!this.sourceLocale || this.locale !== this.sourceLocale) {
this.warn('No translation was found for msgid "' + msgid + '" in msgctxt "' + msgctxt + '" and domain "' + domain + '"');

@@ -399,3 +413,3 @@ }

Gettext.prototype.setlocale = function(locale) {
this.setLomain(locale);
this.setLocale(locale);
};

@@ -402,0 +416,0 @@

{
"name": "node-gettext",
"description": "A JavaScript implementation of gettext, a localization framework",
"version": "2.0.0",
"version": "2.1.0",
"author": "Andris Reinman",

@@ -36,3 +36,3 @@ "maintainers": [

"devDependencies": {
"chai": "^3.5.0",
"chai": "^4.2.0",
"grunt": "^1.0.1",

@@ -42,5 +42,5 @@ "grunt-cli": "^1.2.0",

"grunt-mocha-test": "^0.12.7",
"jsdoc-to-markdown": "^3.0.0",
"mocha": "^2.4.5",
"sinon": "^1.17.7"
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^7.1.1",
"sinon": "^9.0.1"
},

@@ -47,0 +47,0 @@ "engine": {

@@ -108,4 +108,4 @@

const fileName = `${domain}.po`
const translationsFilePath = path.join(translationsDir, locale, filename)
const translationsContent = fs.readSync(translationsFilePath)
const translationsFilePath = path.join(translationsDir, locale, fileName)
const translationsContent = fs.readFileSync(translationsFilePath)

@@ -148,6 +148,7 @@ const parsedTranslations = po.parse(translationsContent)

**Returns**: <code>Object</code> - A Gettext instance
**Returns**: <code>Object</code> - A Gettext instance
**Params**
- `[options]`: <code>Object</code> - A set of options
- `.sourceLocale`: <code>String</code> - The locale that the source code and its texts are written in. Translations for this locale is not necessary.
- `.debug`: <code>Boolean</code> - Whether to output debug info into the

@@ -391,3 +392,4 @@ console.

* [gettext-parser](https://github.com/smhg/gettext-parser) - Parsing and compiling gettext translations between .po/.mo files and JSON
* [react-gettext-parser](https://github.com/lagetse/react-gettext-parser) - Extracting gettext translatable strings from JS(X) code
* [narp](https://github.com/lagetse/narp) - Workflow CLI tool that syncs translations between your app and Transifex
* [lioness](https://github.com/alexanderwallin/lioness) – Gettext library for React
* [react-gettext-parser](https://github.com/laget-se/react-gettext-parser) - Extracting gettext translatable strings from JS(X) code
* [narp](https://github.com/laget-se/narp) - Workflow CLI tool that syncs translations between your app and Transifex

@@ -20,2 +20,36 @@ 'use strict';

describe('#constructor', function() {
var gtc;
beforeEach(function() {
gtc = null;
});
describe('#sourceLocale option', function() {
it('should accept any string as a locale', function() {
gtc = new Gettext({ sourceLocale: 'en-US' });
expect(gtc.sourceLocale).to.equal('en-US');
gtc = new Gettext({ sourceLocale: '01234' });
expect(gtc.sourceLocale).to.equal('01234');
});
it('should default to en empty string', function() {
expect((new Gettext()).sourceLocale).to.equal('');
});
it('should reject non-string values', function() {
gtc = new Gettext({ sourceLocale: null });
expect(gtc.sourceLocale).to.equal('');
gtc = new Gettext({ sourceLocale: 123 });
expect(gtc.sourceLocale).to.equal('');
gtc = new Gettext({ sourceLocale: false });
expect(gtc.sourceLocale).to.equal('');
gtc = new Gettext({ sourceLocale: {} });
expect(gtc.sourceLocale).to.equal('');
gtc = new Gettext({ sourceLocale: function() {} });
expect(gtc.sourceLocale).to.equal('');
});
});
});
describe('#getLanguageCode', function() {

@@ -257,2 +291,11 @@ it('should normalize locale string', function() {

});
it('should not emit any error events when the current locale is the default locale', function() {
var gtd = new Gettext({ sourceLocale: 'en-US' });
var errorListenersourceLocale = sinon.spy();
gtd.on('error', errorListenersourceLocale);
gtd.setLocale('en-US');
gtd.gettext('This message is not translated');
expect(errorListenersourceLocale.callCount).to.equal(0);
});
});

@@ -259,0 +302,0 @@

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