From 44e0ac7038f45c30d7e6612ea6698fedfbd0d159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esben=20Anker-M=C3=B8ller?= Date: Fri, 29 May 2020 17:27:39 +0200 Subject: [PATCH] Make sure to throw an error when no translation is found --- HTMLCS.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/HTMLCS.js b/HTMLCS.js index c209f2c0..90974d37 100755 --- a/HTMLCS.js +++ b/HTMLCS.js @@ -81,11 +81,19 @@ _global.HTMLCS = new function() * @return {String} */ this.getTranslation = function(text) { - try { - return _global.translation[this.lang][text]; - } catch (e) { + var translations = _global.translation[this.lang]; + + if (!translations) { + throw new Error ('Missing translations for language ' + this.lang); + } + + var translation = translations[text]; + + if (!translation) { throw new Error('Translation for "' + text + '" does not exist in current language ' + this.lang); } + + return translation; }; /**