From 1692efb64af4054a0643a99ad96591a795d2a385 Mon Sep 17 00:00:00 2001 From: Diogo Resende Date: Wed, 16 Mar 2011 23:26:12 +0000 Subject: [PATCH] added dgettext(domain, msgid) - this is the same as textdomain(domain) + gettext(msgid); remember to run the test.js on the test folder as it uses relative paths for LC_MESSAGES --- src/node_locale.cc | 26 ++++++++++++++++++++++++++ src/test/test.js | 6 ++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/node_locale.cc b/src/node_locale.cc index dcc051c..92ddf29 100644 --- a/src/node_locale.cc +++ b/src/node_locale.cc @@ -128,6 +128,31 @@ static Handle node_gettext(const Arguments& args) { return scope.Close(String::New(gettext(*text))); } +/** + * dgettext(domain, text) + * + * Get converted using . + * + **/ +static Handle 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) * @@ -280,6 +305,7 @@ void Init(Handle 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); diff --git a/src/test/test.js b/src/test/test.js index fc1fe06..f549f93 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -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); }