Allow translation with numerical token replacement

Just escapes the special regex characters when creating a new RegExp so
that numerical keys can be used (e.g. my use case of replacing an
arbitrary number of tokens from an array). Otherwise it is interpreted
as a repetition.
This commit is contained in:
SilentSpike
2019-12-07 19:12:06 +00:00
parent 09e7b23665
commit af5b64a477

View File

@@ -45,7 +45,7 @@ export function t(s, o, loc) {
if (rep !== undefined) {
if (o) {
for (var k in o) {
var variable = '{' + k + '}';
var variable = '\\{' + k + '\\}';
var re = new RegExp(variable, 'g'); // check globally for variables
rep = rep.replace(re, o[k]);
}
@@ -124,4 +124,4 @@ export function languageName(context, code, options) {
}
}
return code; // if not found, use the code
}
}