New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-gettext-sprintf

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gettext-sprintf - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

7

index.js

@@ -64,3 +64,8 @@ var vsprintf = require("sprintf-js").vsprintf;

dngettext: dngettext,
dnpgettext: dnpgettext
dnpgettext: dnpgettext,
// Sugar, since not everyone has read the gettext manual :)
getSingularText: dgettext,
getSingularTextInContext: dpgettext,
getSingularOrPluralText: dngettext,
getSingularOrPluralTextInContext: dnpgettext
};

@@ -67,0 +72,0 @@ }

2

package.json
{
"name": "node-gettext-sprintf",
"version": "0.0.7",
"version": "0.0.8",
"description": "A combination of node-gettext and sprintf",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,16 +23,65 @@ #node-gettext-sprintf

/*
Given a PO in this form:
msgid ""
msgstr ""
"Language: test0"
"MIME-Version: 1.0"
"Content-Type: text/plain; charset=UTF-8"
"Content-Transfer-Encoding: 8bit"
"Plural-Forms: nplurals=2; plural=(n != 1);"
msgid "Simple string"
msgstr "Simple string translated"
msgid "1 string, 1 int place-holder: %s, %d"
msgstr "1 string, 1 int place-holder: %s, %d translated"
msgid "Simple string singular"
msgstr[0] "Simple string translated"
msgstr[1] "Simple string translated plural"
msgid "Simple string singular int place-holder: %d"
msgstr[0] "Simple string translated int place-holder: %d"
msgstr[1] "Simple string translated plural int place-holder: %d"
msgctxt "Test Context"
msgid "Simple string in context"
msgstr "Simple string in context translated"
msgctxt "Test Context"
msgid "Simple string singular in context int place-holder: %d"
msgstr[0] "Simple string in context translated int place-holder: %d"
msgstr[1] "Simple string in context translated plural int place-holder: %d"
*/
// load the 'test' language
languageFns = getText('test');
languageFns.getText("Simple string");
languageFns.getSingularText("Simple string");
// returns "Simple string translated"
languageFns.getText("1 string, 1 int place-holder: %s, %d", "test-string", 30);
languageFns.getSingularText("1 string, 1 int place-holder: %s, %d", "test-string", 30);
// returns "1 string, 1 int place-holder: test-string, 30 translated"
languageFns.getTextPlural("Simple string singular", 2);
languageFns.getSingularOrPluralText("Simple string singular", 2);
// returns "Simple string translated plural"
languageFns.getTextPlural("Simple string singular int place-holder: %d", 2, 20);
languageFns.getSingularOrPluralText("Simple string singular int place-holder: %d", 2, 20);
// returns "Simple string translated plural int place-holder: 20"
languageFns.getSingularTextInContext("Test Context", "Simple string in context")
// returns "Simple string in context translated"
fns.getSingularOrPluralTextInContext("Test Context", "Simple string singular in context int place-holder: %d", 2, 20),
// returns "Simple string in context translated plural int place-holder: 20"
```
The following standard gettext methods are also supported:
```
dgettext (getSingularText)
dpgettext (getSingularTextInContext)
dngettext (getSingularOrPluralText)
dnpgettext (getSingularOrPluralTextInContext)
```

@@ -17,3 +17,3 @@ var fs = require('fs');

var fns = languageFns('test0');
t.equal(fns.dgettext("test0 - Simple string"), "test0 - Simple string translated");
t.equal(fns.getSingularText("test0 - Simple string"), "test0 - Simple string translated");
t.end();

@@ -24,4 +24,10 @@ });

var fns = languageFns('test0');
t.equal(fns.dgettext("test0 - 1 string place-holder: %s", "test-string"), "test0 - 1 string place-holder: test-string translated");
t.equal(fns.dgettext("test0 - 1 string, 1 int place-holder: %s, %d", "test-string", 30), "test0 - 1 string, 1 int place-holder: test-string, 30 translated");
t.equal(
fns.getSingularText("test0 - 1 string place-holder: %s", "test-string"),
"test0 - 1 string place-holder: test-string translated"
);
t.equal(
fns.getSingularText("test0 - 1 string, 1 int place-holder: %s, %d", "test-string", 30),
"test0 - 1 string, 1 int place-holder: test-string, 30 translated"
);
t.end();

@@ -32,3 +38,6 @@ });

var fns = languageFns('test0');
t.equal(fns.dngettext("test0 - Simple string singular", 2), "test0 - Simple string translated plural");
t.equal(
fns.getSingularOrPluralText("test0 - Simple string singular", 2),
"test0 - Simple string translated plural"
);
t.end();

@@ -39,16 +48,46 @@ });

var fns = languageFns('test0');
t.equal(fns.dngettext("test0 - Simple string singular int place-holder: %d", 2, 20), "test0 - Simple string translated plural int place-holder: 20");
t.equal(
fns.getSingularOrPluralText("test0 - Simple string singular int place-holder: %d", 2, 20),
"test0 - Simple string translated plural int place-holder: 20"
);
t.end();
});
test('Simple strings work with context', function(t) {
var fns = languageFns('test0');
t.equal(
fns.getSingularTextInContext("test0 - Test Context", "test0 - Simple string in context"),
"test0 - Simple string in context translated"
);
t.end();
});
test('sprintf plural place-holder strings work with context', function(t) {
var fns = languageFns('test0');
t.equal(
fns.getSingularOrPluralTextInContext("test0 - Test Context", "test0 - Simple string singular in context int place-holder: %d", 2, 20),
"test0 - Simple string in context translated plural int place-holder: 20"
);
t.end();
});
test('switching language works', function(t) {
var fns = languageFns('test0');
t.equal(fns.dgettext("test0 - Simple string"), "test0 - Simple string translated");
t.equal(
fns.getSingularText("test0 - Simple string"),
"test0 - Simple string translated"
);
fns = languageFns('test1');
t.equal(fns.dgettext("test1 - Simple string"), "test1 - Simple string translated");
t.equal(
fns.getSingularText("test1 - Simple string"),
"test1 - Simple string translated"
);
fns = languageFns('test0');
t.equal(fns.dgettext("test0 - Simple string"), "test0 - Simple string translated");
t.equal(
fns.getSingularText("test0 - Simple string"),
"test0 - Simple string translated"
);
t.end();
});

Sorry, the diff of this file is not supported yet

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