CB Translations

6 months 3 weeks ago #335336 by activha
CB Translations was created by activha
Hello

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 :
  'CHATS_DELETE_ALL_CHATS' => '<form id="deleteForm" action="index.php?option=com_comprofiler&amp;view=pluginclass&amp;plugin=cbautoactions&amp;action=action&amp;actions=340&amp;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 &eacute;l&eacute;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 ?

Thanks for your input

Please Log in to join the conversation.

6 months 3 weeks ago #335337 by krileon
Replied by krileon on topic CB Translations
Use the Translate substitution shown on our substitution tutorial below.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

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:
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.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.153 seconds