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

node-gettext

Package Overview
Dependencies
Maintainers
1
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 0.2.11 to 0.2.12

test/comments.po

18

lib/domain.js

@@ -214,2 +214,5 @@ var Iconv = require("iconv").Iconv,

this._translationTable[context][po[i].msgid || ""] = po[i].msgstr || "";
if(po[i].comments){
this._translationTable[context]["\x05" + (po[i].msgid || "")] = po[i].comments;
}
}

@@ -425,2 +428,17 @@ }

/**
* Retrieves a comment object for a translation
*
* @param {String} original String to be translated
* @param {String} [context] Translation context
* @return {Object|Boolean} Comment object for the translation
*/
GettextDomain.prototype.getComment = function(original, context){
context = (context || "").toString();
return this._translationTable[context] &&
this._translationTable[context]["\x05" + original]
false;
};
/**
* Adds/replaces a translation in the translation table

@@ -427,0 +445,0 @@ *

33

lib/gettext.js

@@ -76,3 +76,3 @@

Gettext.prototype.gettext = function(msgid){
return this._getTranslation(false, msgid) || msgid;
return this.dnpgettext(false, false, msgid);
};

@@ -88,3 +88,3 @@

Gettext.prototype.dgettext = function(domain, msgid){
return this._getTranslation(domain, msgid) || msgid;
return this.dnpgettext(domain, false, msgid);
};

@@ -101,3 +101,3 @@

Gettext.prototype.ngettext = function(msgid, msgidPlural, count){
return this.dngettext(false, msgid, msgidPlural, count);
return this.dnpgettext(false, false, msgid, msgidPlural, count);
};

@@ -115,7 +115,3 @@

Gettext.prototype.dngettext = function(domain, msgid, msgidPlural, count){
var defaultTranslation = msgid;
if(!isNaN(count) && count != 1){
defaultTranslation = msgidPlural;
}
return this._getTranslation(domain, msgid, false, count) || defaultTranslation;
return this.dnpgettext(domain, false, msgid, msgidPlural, count);
};

@@ -131,3 +127,3 @@

Gettext.prototype.pgettext = function(context, msgid){
return this._getTranslation(false, msgid, context) || msgid;
return this.dnpgettext(false, context, msgid);
};

@@ -145,2 +141,3 @@

return this._getTranslation(domain, msgid, context) || msgid;
return this.dnpgettext(domain, context, msgid);
};

@@ -179,3 +176,21 @@

/**
* Retrieves comments for a translation
*
* @param {String} domain Case insensitive language identifier
* @param {String} context Translation context
* @param {String} msgid String to be translated
* @return {Object} comments for the translation in the form of {comment, note, code}
*/
Gettext.prototype.getComment = function(domain, context, msgid){
domain = (domain || this._textdomain || "").toLowerCase().trim();
if(this._domains[domain]){
return this._domains[domain].getComment(msgid, context);
}else{
return false;
}
};
/**
* Adds/replaces a translation in the translation table

@@ -182,0 +197,0 @@ *

@@ -121,3 +121,3 @@ var Iconv = require("iconv").Iconv;

state = this.states.none;
}else if(chr != "\r" && (chr != " " || node.value.length)){
}else if(chr != "\r"){
node.value += chr;

@@ -186,4 +186,38 @@ }

//console.log(response);
// parse comments
lex.forEach((function(node){
var comment, lines;
if(node && node.type == this.types.comments){
comment = {code: [], comment: [], note: []};
lines = (node.value || "").split(/\n/);
lines.forEach(function(line){
switch(line.charAt(0) || ""){
case ":":
comment.code.push(line.substr(1).trim());
break;
case ".":
comment.note.push(line.substr(1).replace(/^\s+/, ""));
break;
default:
comment.comment.push(line.replace(/^\s+/, ""));
}
});
node.value = {};
if(comment.comment.length){
node.value.comment = comment.comment.join("\n");
}
if(comment.note.length){
node.value.note = comment.note.join("\n");
}
if(comment.code.length){
node.value.code = comment.code.join("\n");
}
}
}).bind(this));
lex = response;

@@ -212,3 +246,3 @@ response = [];

lastNode = false;
// group originals with translations and context

@@ -232,4 +266,4 @@ for(var i=0, len = lex.length; i<len; i++){

if(lex[i].comments){
lastNode.comments = (lastNode.comments || "") + (lastNode.comments ? "\n" : "") + lex[i].comments;
if(lex[i].comments && !lastNode.comments){
lastNode.comments = lex[i].comments;
}

@@ -245,4 +279,4 @@

if(lex[i].comments){
lastNode.comments = (lastNode.comments || "") + (lastNode.comments ? "\n" : "") + lex[i].comments;
if(lex[i].comments && !lastNode.comments){
lastNode.comments = lex[i].comments;
}

@@ -254,4 +288,4 @@

}
return response;
}
{
"name": "node-gettext",
"description": "Gettext client for Node.js to use .mo files for I18N",
"version": "0.2.11",
"version": "0.2.12",
"author" : "Andris Reinman",

@@ -6,0 +6,0 @@ "maintainers":[

@@ -116,2 +116,10 @@ # node-gettext

### Get comments for a translation (if loaded from PO)
*getComment(domain, msgctxt, msgid)*
gt.getComment("et", "menu items", "%d Recent File");
Returns an object in the form of `{comment: "", code: "", note: ""}`
## String helpers

@@ -118,0 +126,0 @@

@@ -443,2 +443,24 @@ var testCase = require('nodeunit').testCase,

}
}
exports["COMMENTS"] = {
setUp: function (callback) {
fs.readFile(__dirname+"/comments.po", (function(err, body){
if(err){
throw err;
}
this.g = new Gettext();
this.g.addTextdomain("et", body);
callback();
}).bind(this));
},
"Normal comments": function(test){
test.deepEqual(this.g.getComment("et", "", "test"),
{
comment: 'Normal comment line 1\nNormal comment line 2',
note: 'Editors note line 1\nEditors note line 2',
code: '/absolute/path:13\n/absolute/path:14'
});
test.done();
}
}

Sorry, the diff of this file is not supported yet

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