Skip to content
Snippets Groups Projects
Commit 27fddb26 authored by Austin King's avatar Austin King
Browse files

Removing copy of GPL Gettext.js strargs function

parent 9e12c067
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment