From 2387ff54c0f3ff47e175b103355b4d7aa9aa2e94 Mon Sep 17 00:00:00 2001 From: 50h100a Date: Tue, 11 Jul 2023 03:15:30 -0400 Subject: [PATCH] Add i18n attribute-keying syntax to this very-much-not i18n loc code. --- public/index.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index cad011ad1..27bbd3108 100644 --- a/public/index.html +++ b/public/index.html @@ -57,10 +57,20 @@ //find all the elements with `data-i18n` attribute $("[data-i18n]").each(function () { //read the translation from the language data - const key = $(this).data("i18n"); - const text = data?.[language]?.[key]; // Ensure that the translated text is loaded correctly. - if (text) { - $(this).text(text); + const keys = $(this).data("i18n").split(';'); // Multi-key entries are ; delimited + for (const key of keys) { + const attrmatch = key.match(/\[(\S+)\](.+)/); // [attribute]key + if (attrmatch) { // attribute-tagged key + const locval = data?.[language]?.[attrmatch[2]]; + if (locval) { + $(this).attr(attrmatch[1], locval); + } + } else { // No attribute tag, treat as 'text' + const locval = data?.[language]?.[key]; + if (locval) { + $(this).text(locval); + } + } } }); });