Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3104570

Browse files
committed
[i18n] only append tail if it is actually needed
Signed-off-by: Michael Telatynski <[email protected]>
1 parent b5daba9 commit 3104570

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/languageHandler.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ export function replaceByRegexes(text, mapping) {
177177
// If we insert any components we need to wrap the output in a span. React doesn't like just an array of components.
178178
let shouldWrapInSpan = false;
179179

180+
if (text === "You are now ignoring %(userId)s") {
181+
debugger;
182+
}
183+
180184
for (const regexpString in mapping) {
181185
// TODO: Cache regexps
182186
const regexp = new RegExp(regexpString, "g");
@@ -233,11 +237,15 @@ export function replaceByRegexes(text, mapping) {
233237

234238
// add the text between prevMatch and this one
235239
// or the end of the string if prevMatch is the last match
240+
let tail;
236241
if (match) {
237242
const startIndex = prevMatch.index + prevMatch[0].length;
238-
parts.push(inputText.substr(startIndex, match.index - startIndex));
243+
tail = inputText.substr(startIndex, match.index - startIndex);
239244
} else {
240-
parts.push(inputText.substr(prevMatch.index + prevMatch[0].length));
245+
tail = inputText.substr(prevMatch.index + prevMatch[0].length);
246+
}
247+
if (tail) {
248+
parts.push(tail);
241249
}
242250
}
243251

test/i18n-test/languageHandler-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ describe('languageHandler', function() {
7373

7474
it('multiple replacements of the same variable', function() {
7575
const text = '%(var1)s %(var1)s';
76-
expect(languageHandler._t(text, { var1: 'val1' })).toBe('val1 val1');
76+
expect(languageHandler.substitute(text, { var1: 'val1' })).toBe('val1 val1');
7777
});
7878

7979
it('multiple replacements of the same tag', function() {
8080
const text = '<a>Click here</a> to join the discussion! <a>or here</a>';
81-
expect(languageHandler._t(text, {}, { 'a': (sub) => `x${sub}x` }))
81+
expect(languageHandler.substitute(text, {}, { 'a': (sub) => `x${sub}x` }))
8282
.toBe('xClick herex to join the discussion! xor herex');
8383
});
8484
});

0 commit comments

Comments
 (0)