From e899d76f69f4ee7525c34e96713dbb15b400f8f3 Mon Sep 17 00:00:00 2001 From: mic Date: Tue, 16 Jul 2024 22:42:39 +0200 Subject: [PATCH] i18nConditionalGet method added. see #20 --- js/mzta-utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 1e5e9bfc..fc87deee 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -134,4 +134,16 @@ const insertHtml = function (replyHtml, fullBody_string) { }); fullBody.body.insertBefore(fragment, fullBody.body.firstChild); return fullBody.body.innerHTML; +} + +export function i18nConditionalGet(str) { + // if we are getting a string that starts with '__MSG_' and ends with '__' we return the translated string + // using the browser.i18n API + // else we return the original string + // Check if the string starts with '__MSG_' and ends with '__' + if (str.startsWith('__MSG_') && str.endsWith('__')) { + // Remove '__MSG_' from the beginning and '__' from the end + return browser.i18n.getMessage(str.substring(6, str.length - 2)); + } + return str; // Return the original string if the conditions are not met } \ No newline at end of file