Skip to content

Commit

Permalink
added dgettext(domain, msgid) - this is the same as textdomain(domain…
Browse files Browse the repository at this point in the history
…) + gettext(msgid); remember to run the test.js on the test folder as it uses relative paths for LC_MESSAGES
  • Loading branch information
dresende committed Mar 16, 2011
1 parent c01f278 commit 1692efb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/node_locale.cc
Expand Up @@ -128,6 +128,31 @@ static Handle<Value> node_gettext(const Arguments& args) {
return scope.Close(String::New(gettext(*text)));
}

/**
* dgettext(domain, text)
*
* Get converted <text> using <domain>.
*
**/
static Handle<Value> node_dgettext(const Arguments& args) {
HandleScope scope;

if (args.Length() < 2) {
return ThrowException(Exception::TypeError(String::New("Missing argument")));
}
if (!args[0]->IsString()) {
return ThrowException(Exception::TypeError(String::New("Argument 1 must be a domain string")));
}
if (!args[1]->IsString()) {
return ThrowException(Exception::TypeError(String::New("Argument 2 must be a string")));
}

String::Utf8Value domain(args[0]->ToString());
String::Utf8Value text(args[1]->ToString());

return scope.Close(String::New(dgettext(*domain, *text)));
}

/**
* strfmon(format, value)
*
Expand Down Expand Up @@ -280,6 +305,7 @@ void Init(Handle<Object> target) {
NODE_SET_METHOD(target, "bindtextdomain", node_bindtextdomain);
NODE_SET_METHOD(target, "textdomain", node_textdomain);
NODE_SET_METHOD(target, "gettext", node_gettext);
NODE_SET_METHOD(target, "dgettext", node_dgettext);
NODE_SET_METHOD(target, "strfmon", node_strfmon);
NODE_SET_METHOD(target, "strftime", node_strftime);
NODE_SET_METHOD(target, "strptime", node_strptime);
Expand Down
6 changes: 4 additions & 2 deletions src/test/test.js
Expand Up @@ -29,8 +29,10 @@ try {
console.dir(locale.strptime(dts, "%D %T"));

console.log("bindtextdomain('test', './') -> " + locale.bindtextdomain("test", "./"));
console.log("textdomain('test') -> " + locale.textdomain("test"));
console.log("gettext('hello test') -> " + locale.gettext("hello test"));
//console.log("textdomain('test') -> " + locale.textdomain("test"));
//console.log("gettext('hello test') -> " + locale.gettext("hello test"));
// instead of the 2 above lines you could just..
console.log("dgettext('test', 'hello test') -> " + locale.dgettext("test", "hello test"));
} catch (e) {
console.log("Exception: " + e.message);
}

0 comments on commit 1692efb

Please sign in to comment.