By adding a little bit of JS to the page, I managed to translate the “is a required field” string on the fly. Maybe that’s a workaround for other users too. But it would be nice to have it as part of the cool CS Form element.
document.addEventListener('DOMContentLoaded', function () {
function translateRequiredMessages(root) {
root = root || document.body;
var walker = document.createTreeWalker(
root,
NodeFilter.SHOW_TEXT
);
var node;
while ((node = walker.nextNode())) {
if (
node.nodeValue &&
node.nodeValue.includes('is a required field')
) {
node.nodeValue = node.nodeValue.replace(
/is a required field/g,
'ist ein Pflichtfeld'
);
}
}
}
translateRequiredMessages();
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (node.nodeType === Node.TEXT_NODE) {
if (
node.nodeValue &&
node.nodeValue.includes('is a required field')
) {
node.nodeValue = node.nodeValue.replace(
/is a required field/g,
'ist ein Pflichtfeld'
);
}
} else if (node.nodeType === Node.ELEMENT_NODE) {
translateRequiredMessages(node);
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});