From af5b64a477b9afaae83ccbe808da9b271343c49f Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sat, 7 Dec 2019 19:12:06 +0000 Subject: [PATCH] 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. --- modules/util/locale.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/util/locale.js b/modules/util/locale.js index 44710a546..e003b759b 100644 --- a/modules/util/locale.js +++ b/modules/util/locale.js @@ -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 -} +} \ No newline at end of file