From 1d29ee6d87d3794a9319bca5bf36afdfe176072c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 1 Sep 2023 22:32:45 +0200 Subject: translations with fallback --- resources/js/helpers.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'resources/js/helpers.js') diff --git a/resources/js/helpers.js b/resources/js/helpers.js index aa149b1..cee9166 100644 --- a/resources/js/helpers.js +++ b/resources/js/helpers.js @@ -68,14 +68,19 @@ function randomString () { /** * @param {string} msgid + * @param {boolean} useFallback * * @returns {string} */ -function translate (msgid, showTranslationMissing = false) { +function translate (msgid, useFallback = true) { let translation = DB.translations[Memory.state.Settings.language][msgid]; - if (!translation && showTranslationMissing) { - translation = (translate('translation_missing') || 'translation_missing') + `: ${msgid}`; + if (!translation && useFallback) { + translation = DB.translations['en_US'][msgid]; + + if (!translation) { + translation = (translate('translation_missing', false) || 'translation_missing') + `: ${msgid}`; + } } return translation; @@ -89,7 +94,7 @@ function applyTranslation () { } parentNode.querySelectorAll('[data-i18n-msgid]').forEach((node) => { - node.innerHTML = translate(node.dataset.i18nMsgid, true); + node.innerHTML = translate(node.dataset.i18nMsgid); }); parentNode.querySelectorAll('[data-i18n-properties]').forEach((node) => { @@ -99,7 +104,7 @@ function applyTranslation () { const property = properties[idx]; const msgid = msgids[idx]; - node.setAttribute(property, translate(msgid, true)) + node.setAttribute(property, translate(msgid)) } }); }); -- cgit v1.2.3