diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-01 22:32:45 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-09-01 22:32:45 +0200 |
commit | 1d29ee6d87d3794a9319bca5bf36afdfe176072c (patch) | |
tree | 1e7e89ca87afd313b1806fcc80d456796b0af6db /resources/js/helpers.js | |
parent | 6b3a8aef783368d0ed9a2c104eea3ff5cf9984da (diff) |
translations with fallback
Diffstat (limited to 'resources/js/helpers.js')
-rw-r--r-- | resources/js/helpers.js | 15 |
1 files changed, 10 insertions, 5 deletions
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)) } }); }); |