From 4673875ec9563237fc5dd80cf74cd5e22f980b06 Mon Sep 17 00:00:00 2001 From: Manuel Kocher <manuel.kocher@tugraz.at> Date: Wed, 9 Nov 2022 16:13:20 +0100 Subject: [PATCH] Move i18n.t override function used for testing to frontend debug mode --- packages/common/i18next.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/common/i18next.js b/packages/common/i18next.js index 7fcd05b7..2ece798c 100644 --- a/packages/common/i18next.js +++ b/packages/common/i18next.js @@ -125,16 +125,19 @@ export function createInstance(languages, lng, fallback, namespace) { i18n.init(options); console.assert(i18n.isInitialized); - const translate = i18n.t; - const that = i18n; - - i18n.t = function (keys, options) { - if (!that.exists(keys)) { - console.error("Error: Translation key " + keys + " does not exist!"); - } - - return translate(keys, options); - }; + // if debug mode is activated, override i18n.t() to print errors if keys are missing + if (window.location.hash.includes('debug')) { + const translate = i18n.t; + const that = i18n; + + i18n.t = function (keys, options) { + if (!that.exists(keys)) { + console.error("Error: Translation key " + keys + " does not exist!"); + } + + return translate(keys, options); + }; + } return i18n; } -- GitLab