Babel, some questions

I am studying in detail the always fantastic Babel component.
My notes referred to links that no longer exist, so I will present some doubts as I encounter them.

First of all, what does the restrictToGroup setting do?
I saw it used in the babellinks.php snippet but didn’t quite understand what it limits.
If someone can give me some help, maybe with some practical examples, I thank you in advance.

You can set up your MODX instance to handle multiple websites. Now if several of those multiple websites are also multi-lingual (and therefore consist of multiple contexts), you can define so called context groups (in the system setting babel.contextKeys) to indicate which contexts belong together.

With restrictToGroup you can define, if these context groups are taken into account or being ignored.

If you don’t have multiple websites and all the contexts in babel.contextKeys are in one single group, this setting has not effect and can safely be ignored.


Maybe you can use the Wayback machine to access the content and copy it.

Thank you.
You always bring light to my mental darkness :grinning_face:

I didn’t understand the context groups, which are the definitions with the ; in babel.contextKeys. I believe I will never use them, so I’m clearing this doubt and true or false for restrictToGroup doesn’t matter to me (I exclusively use a single site and the contexts are only the versions in other languages). Provided I understood correctly.

I use “webmachine” (waybackmachine) but the fact of using it already gives me the idea that the information it provides is obsolete and no longer accurate. :grinning_face:

I will provide further questions shortly. :blush:

About permissions
I saw in the docs that there is babel_setting, it blocks access to the CMP that manages everything, right?
Do I need to add it to the policy template and to the permission field of the menu for it to work?

And what about hiding the translation button at the top next to save?
Is there a permission?

There is a psermission babel_settings (with an s at the end).
As far as I can tell, it only blocks the access to the “settings” tab of the Babel CMP (“Extras” → “Babel” → tab “:gear:”).

The extra adds a new “Policy Template” → BabelTemplate and a new “Access Policy” → Babel that you can use for the user groups.

I don’t think there are any permission checks for this button in the code.

Thank you, you didn’t notice it was creating a new template and a new policy.
Nevertheless, I believe that adding the permission babel_settings to the policies I use.
For the translation button, it’s a shame, it would have been very useful.
However, I imagine that other permissions are respected in the button, so groups that cannot create resources will not be able to create translations and groups that cannot delete resources will not be able to delete translations, right?

Some questions after reading the documentation and doing some tests
The option
Synchronize all translations
what is it used for in practice?
Both when creating multiple translations, creating a single translation, and updating (refresh) a translation, whether it is selected or not does not change the result; all (or the single resource if I update only one translation) are cloned exactly as they are, with all fields copied.

And the option
Copy synchronized TVs to target
what is it used for?
If the TVs and the Fields are synchronized, they automatically update with every change

This setting only affects the values of the (hidden) TV “babelLanguageLinks”, that is used by Babel to link the ‘same’ resources across the different language contexts.

Let’s say for example you have a web context and the two contexts en and fr.
If you create a new resource in web and then select “Create translation” for the other two contexts and both times check “ Synchronize all translations”, all three resources are linked to one another.

If you create a new resource in web and then select “Create translation” for the other two contexts and don’t check “ Synchronize all translations”, the resource in en is only linked to the resource in web and the same is true for the resource in fr. (You then have to go to the Babel CMP and manually add the missing link between en and fr.)


What exact action (“link”, “refresh”, … ?) do you take, when you have to decide whether to check or uncheck this option?
I guess it can be used to synchronize the TVs/fields right at the moment the action is taken, and not only when one of the linked resources is saved the next time.

Thank you.

Synchronize all translations
I had read the documentation but didn’t see any differences in Babel’s CMP, so I asked.
A minor issue, I always keep it checked
It was more to enhance my knowledge of the component.

Copy synchronized TVs to target
For any action, the option appears: create, create multiple, refresh, refresh multiple
What is not clear to me is that if I have declared a TVs (or Fields) as synchronized, each time I modify it, it updates automatically
Furthermore, if I create or refresh a resource, it is exactly cloned in the translation, so I don’t understand what the option is for there

Regarding the translation button next to save in modx-action-buttons
I would like the Babel ones to be visible only to the groups I choose, to prevent, for example, the lawyers’ group from synchronizing (deleting translations) or creating translations that are not their responsibility
I know that with the solution I’m presenting, I have to modify the file with each update, but I always note everything in a dedicated file
Here’s what I did and it works
I created a new permission in the policy template amab_use_babel
I modified the file core\components\babel\src\Plugins\Events\OnDocFormPrerender.php
Inserting the if statements permission shown below

if ($this->babel->getOption('debug') && ($this->babel->getOption('assetsUrl') != MODX_ASSETS_URL . 'components/babel/')) {
            $this->modx->controller->addCss($cssSourceUrl . 'babel.css?v=v' . $this->babel->version);
            $this->modx->controller->addJavascript($jsSourceUrl . 'babel.js?v=v' . $this->babel->version);
        } else {
            $this->modx->controller->addCss($cssUrl . 'resourcebutton.min.css?v=v' . $this->babel->version);
			if($this->modx->hasPermission('amab_use_babel')){
            $this->modx->controller->addJavascript($jsUrl . 'resourcebutton.min.js?v=v' . $this->babel->version);
			}
        }
		if($this->modx->hasPermission('amab_use_babel')){
        $this->modx->controller->addHtml('<script type="text/javascript">
        Ext.onReady(function () {
            Babel.config = ' . json_encode($this->babel->config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ';
            Babel.getMenu(Babel.config.menu);
        });
        </script>');
		}

As I mentioned, it works and I don’t have any console errors for any group
Besides the need to update the file with each update, could this modification cause any issues?
Thanks

Let’s say you have two unlinked resources (in different contexts) that have different values in the synchronized TVs. Now if you select “Link to existing resource” (in the Babel CMP) and don’t select “ Copy synchronized TVs to target”, the TV values will still be different after the linkage. In this use case, it makes sense to select “ Copy synchronized TVs to target”.


When creating a new translation, the option “Copy synchronized TVs to target” is probably useless, as the original resource (and all its data) will be duplicated for the new translation.

The same seems to be true for “refresh”, where all the fields and TV values are reset to the value of the source-resource anyway.


The button from Babel does have a unique ID:

So maybe it’s possible to hide the button with CSS or JS in a custom plugin, to avoid having to modify the Babel source code. (In JS you can use MODx.perm to access the user permissions.)

1 Like

Than you very much!
Babel.js is minimized, and modifying it is problematic for me. To avoid causing any issues, I use my own technique, which is very rudimentary if it doesn’t create problems.
Sure, with a plugin, all I need only the id :grinning_face:

In the update to 3.5.4, I noticed the following change:

-Use the correct babel.syncTvs and babel.syncFields value during an update

Does this refer to an update of Babel, or has something changed regarding the options for synchronized TVs and Fields?

Nothing has changed. This is just a bug fix. It looks like these settings were (potentially) cast to a boolean during an upgrade of the Babel extra.

See the change (in the file _build/setup.options.php) here on Github:

1 Like