Thanks Sanford,
ok, so let me scratch that approach and go back to my rudimentary homebrew JS then 🙂
This is what I have come up with, it gets the job done for my forms, but does not cater for all the field types probably, or stuff like hint texts or instructions...etc... The code still leverages your translations as formatted in the Codepen. Code below assumes the leadlocale already set.
<script>
// Check if locale is contained in translations (file)
var localeTranslations = mktoFormLanguages.find((obj) => {
return obj.lang === leadlocale;
});
// If that locale is not found in translations file, default to English
if (!localeTranslations) {
localeTranslations = mktoFormLanguages.find((obj) => {
return obj.lang === "United Kingdom - EN";
});
}
// FORM TRANSLATIONS START //
MktoForms2.whenReady(function (form) {
// Translate labels
var xlate_labels = document.getElementsByClassName("mktoLabel");
for (let lbl of xlate_labels) {
lbl.innerText = localeTranslations.translations.fields.find((x) => x.Name === lbl.getAttribute("for")).InputLabel;
}
// Translate picklist values
var xlate_fields = document.getElementsByClassName("mktoField");
for (let fld of xlate_fields) {
if (fld.type === "select-one") {
var optns = fld.options;
for (let optn of optns) {
optn.innerText = localeTranslations.translations.fields.find((x) => x.Name === fld.name).PicklistValues.find((y) => y.value === optn.getAttribute("value")).label;
}
}
}
// Translate Submit button
var xlate_btns = document.getElementsByClassName("mktoButton");
for (let btn of xlate_btns) {
btn.innerText = localeTranslations.translations.core.SubmitLabel;
}
});
// FORM TRANSLATIONS END //
</script>
At least it's working for me now and I can expand on it later, having the structure to capture the translations data in place already.
Cheers!
Thorsten
... View more