From 27fddb260efbfb0e2d8898502cc3738d0662fba5 Mon Sep 17 00:00:00 2001 From: Austin King <shout@ozten.com> Date: Wed, 18 Jan 2012 15:50:17 -0800 Subject: [PATCH] Removing copy of GPL Gettext.js strargs function --- lib/i18n.js | 53 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/lib/i18n.js b/lib/i18n.js index d365aaf9e..32daab9f5 100644 --- a/lib/i18n.js +++ b/lib/i18n.js @@ -180,57 +180,8 @@ exports.localeFrom = localeFrom = function (language) { }; /** - * Copied from `resources/static/shared/gettext.js`, so we can use the - * same method name on node.js and client-side. + * TODO: replace with util.format like function */ exports.strargs = strargs = function (str, args) { - // make sure args is an array - if ( null == args || - 'undefined' == typeof(args) ) { - args = []; - } else if (args.constructor != Array) { - args = [args]; - } - - // NOTE: javascript lacks support for zero length negative look-behind - // in regex, so we must step through w/ index. - // The perl equiv would simply be: - // $string =~ s/(?<!\%)\%([0-9]+)/$args[$1]/g; - // $string =~ s/\%\%/\%/g; # restore escaped percent signs - - var newstr = ""; - while (true) { - var i = str.indexOf('%'); - var match_n; - - // no more found. Append whatever remains - if (i == -1) { - newstr += str; - break; - } - - // we found it, append everything up to that - newstr += str.substr(0, i); - - // check for escpaed %% - if (str.substr(i, 2) == '%%') { - newstr += '%'; - str = str.substr((i+2)); - - // % followed by number - } else if ( match_n = str.substr(i).match(/^%(\d+)/) ) { - var arg_n = parseInt(match_n[1]); - var length_n = match_n[1].length; - if ( arg_n > 0 && args[arg_n -1] != null && typeof(args[arg_n -1]) != 'undefined' ) - newstr += args[arg_n -1]; - str = str.substr( (i + 1 + length_n) ); - - // % followed by some other garbage - just remove the % - } else { - newstr += '%'; - str = str.substr((i+1)); - } - } - - return newstr; + return str; }; \ No newline at end of file -- GitLab