summaryrefslogtreecommitdiff
path: root/resources/js/helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/helpers.js')
-rw-r--r--resources/js/helpers.js36
1 files changed, 34 insertions, 2 deletions
diff --git a/resources/js/helpers.js b/resources/js/helpers.js
index adf0bb7..58e2113 100644
--- a/resources/js/helpers.js
+++ b/resources/js/helpers.js
@@ -59,9 +59,41 @@ function randomString () {
/**
* @param {string} msgid
+ *
+ * @returns {string}
*/
-function translate (msgid) {
- return DB.translations[Memory.state.Settings.language][msgid];
+function translate (msgid, showTranslationMissing = false) {
+ let translation = DB.translations[Memory.state.Settings.language][msgid];
+
+ if (!translation && showTranslationMissing) {
+ translation = (translate('translation_missing') || 'translation_missing') + `: ${msgid}`;
+ }
+
+ return translation;
+}
+
+function applyTranslation () {
+ document.querySelectorAll('body, template').forEach((element) => {
+ let parentNode = element;
+ if (element.content) {
+ parentNode = element.content;
+ }
+
+ parentNode.querySelectorAll('[data-i18n-msgid]').forEach((node) => {
+ node.innerHTML = translate(node.dataset.i18nMsgid, true);
+ });
+
+ parentNode.querySelectorAll('[data-i18n-properties]').forEach((node) => {
+ const properties = node.dataset.i18nProperties.split(',')
+ const msgids = node.dataset.i18nPropertyMsgids.split(',')
+ for (const idx in properties) {
+ const property = properties[idx];
+ const msgid = msgids[idx];
+
+ node.setAttribute(property, translate(msgid, true))
+ }
+ });
+ });
}
/**