I'd like your suggestions about how to deal with translations including scripts.
For instance I have an html field which triggers an url to do an action with a js warning.
In order to translate the field I set the whole in a translation string like this :
Code:
'CHATS_DELETE_ALL_CHATS' => '<form id="deleteForm" action="index.php?option=com_comprofiler&view=pluginclass&plugin=cbautoactions&action=action&actions=340&Itemid=9515" method="post"><div class="mb-3"><label class="form-label">Éléments à supprimer:</label><div class="form-check"><input class="form-check-input" type="checkbox" value="chat" id="chat" name="folders[]"> <label class="form-check-label" for="chat">Affichage des conversations</label></div><div class="form-check"><input class="form-check-input" type="checkbox" value="memory" id="memory" name="folders[]"> <label class="form-check-label" for="memory">Mémoire des conversations</label></div></div><input type="submit" class="btn btn-primary" value="Supprimer tous les éléments"></form><script>
jQuery(document).ready(function($) {
$(`#deleteForm`).submit(function() {
var isChecked = $(`input[type=checkbox]:checked`).length > 0;
if (!isChecked) {
alert(`Veuillez sélectionner au moins un dossier à supprimer.`);
return false;
} else {
return confirm(`Voulez-vous vraiment supprimer toutes ces conversations et ces dossiers ? Attention, cette action est définitive et vos éléments ne pourront plus être récupérés !`);
}
});
});</script>',
Is there any other way to do it ?
Is it safe to add scripts in the override files ?
You can then just translate the language strings inline. Example as follows.
[cb:translate key="FIELD_CONFIRM" /]
Now you'd have a language override as follows.
Key: FIELD_CONFIRM
String:
Code:
Voulez-vous vraiment supprimer toutes ces conversations et ces dossiers ? Attention, cette action est définitive et vos éléments ne pourront plus être récupérés !
Now just use [cb:translate key="FIELD_CONFIRM" /] in your JS in your Custom HTML field.
Kyle (Krileon) Community Builder Team Member Before posting on forums:
Read FAQ thoroughly
+
Read our Documentation
+
Search the forums CB links:
Documentation
-
Localization
-
CB Quickstart
-
CB Paid Subscriptions
-
Add-Ons
-
Forge
-- If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
-- If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please
send me a private message
with your thread and will reply when possible!
-- Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
-- My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.