From a5260cb38a0302f545ff657d84987edd9303cae8 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Mon, 19 Jun 2023 05:06:24 +0200 Subject: [PATCH] feat: improve locale translation not found error (#2853) --- src/common/I18n.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/I18n.js b/src/common/I18n.js index 48242af..8d80a85 100644 --- a/src/common/I18n.js +++ b/src/common/I18n.js @@ -9,15 +9,17 @@ class I18n { } t(str) { + const locale = this.locale || this.fallbackLocale; + if (!this.translations[str]) { throw new Error(`${str} Translation string not found`); } - if (!this.translations[str][this.locale || this.fallbackLocale]) { - throw new Error(`${str} Translation locale not found`); + if (!this.translations[str][locale]) { + throw new Error(`'${str}' translation not found for locale '${locale}'`); } - return this.translations[str][this.locale || this.fallbackLocale]; + return this.translations[str][locale]; } }