From ca3be1f336dfa3f4c93a8734660f235bb4d19a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 16 Oct 2019 13:33:00 -0400 Subject: [PATCH] fix: #7974 (#7976) --- public/src/modules/translator.js | 5 ++++- test/translator.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index a861f8fc39..74d6b867c2 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -541,7 +541,10 @@ } if (!(typeof text === 'string' || text instanceof String) || text === '') { - return cb(''); + if (cb) { + return setTimeout(cb, 0, ''); + } + return ''; } return Translator.create(lang).translate(text).then(function (output) { diff --git a/test/translator.js b/test/translator.js index 43dac6f692..628300166d 100644 --- a/test/translator.js +++ b/test/translator.js @@ -21,6 +21,18 @@ describe('Translator shim', function () { done(); }); }); + + it('should translate empty string properly', function (done) { + shim.translate('', 'en-GB', function (translated) { + assert.strictEqual(translated, ''); + done(); + }); + }); + + it('should translate empty string properly', async function () { + const translated = await shim.translate('', 'en-GB'); + assert.strictEqual(translated, ''); + }); }); });