From 3e51af2cc5486857e4542f4cb65c9587a09b469d Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 24 Dec 2015 11:45:01 +0000 Subject: [PATCH] Don't throw if translating before loading Just return the passed string. This makes initialisation simpler, as a promise is unnecessary. --- src/gui/html/js/translator.js | 3 +++ src/tests/gui/html/js/test_translator.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/html/js/translator.js b/src/gui/html/js/translator.js index bb0e0f13..60720c77 100644 --- a/src/gui/html/js/translator.js +++ b/src/gui/html/js/translator.js @@ -67,6 +67,9 @@ if (text === undefined) { return ''; } + if (this.jed === undefined) { + return text; + } const func = this.jed.translate(text); return func.fetch.apply(func, substitutions); } diff --git a/src/tests/gui/html/js/test_translator.js b/src/tests/gui/html/js/test_translator.js index c48737e6..461b8694 100644 --- a/src/tests/gui/html/js/test_translator.js +++ b/src/tests/gui/html/js/test_translator.js @@ -37,8 +37,8 @@ describe('Translator', () => { l10n = new loot.Translator(); }); - it('should throw if the translator has not been loaded', () => { - (() => { l10n.translate('foo'); }).should.throw(); + it('should return original string if the translator has not been loaded', () => { + l10n.translate('foo').should.equal('foo'); }); it('should return an empty string if nothing is passed', () => {