mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add i18n attribute-keying syntax to this very-much-not i18n loc code.
This commit is contained in:
@@ -57,10 +57,20 @@
|
|||||||
//find all the elements with `data-i18n` attribute
|
//find all the elements with `data-i18n` attribute
|
||||||
$("[data-i18n]").each(function () {
|
$("[data-i18n]").each(function () {
|
||||||
//read the translation from the language data
|
//read the translation from the language data
|
||||||
const key = $(this).data("i18n");
|
const keys = $(this).data("i18n").split(';'); // Multi-key entries are ; delimited
|
||||||
const text = data?.[language]?.[key]; // Ensure that the translated text is loaded correctly.
|
for (const key of keys) {
|
||||||
if (text) {
|
const attrmatch = key.match(/\[(\S+)\](.+)/); // [attribute]key
|
||||||
$(this).text(text);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user