Data Object Tree translations

Hi there,

I was wondering if there was any way to provide translations for Object Keys as they are displayed in the object tree. There could be some post-processing which could involve this kind of logic :

$treeLabel = $keysTranslations[$object->getFullPath()] || $object->getKey()

Here’s a capture of my English based taxonomy, but I’d like to be able to display it in French for French users.
Thanks for your help!

The keys are not meant to be translated, as far as I could tell. They represent a unique entry for a single object. If the keys weren’t unique, then you wouldn’t need to define them on creation. You’d just need an id.

They are used for pretty URLs, however, and I do realize that that could represent an issue. But, if the key in the path is unique, and the name of the object is the same as the key, I think you could get away with creating your own route which takes the name as the parameter (since they’re not Documents and don’t have a fixed translation which also represents a URL), if you get my drift.

I’d also have a look at, but I don’t think you’ll get anything useful about translating keys.

1 Like

I figured out how this could be done. The magic would happen in the AdminBundle DataObjectController.

On line 226, we see that we’re stripping htmlspecialchars. Instead of this, we could use the builtin $this->trans($key) method exposed in the controller to fetch a translation from the admin translations.

If each and every path of the DataObject tree gets translated, I think it could be potentially harmful when there is a bunch of untranslatable items, it would clutter the admin translations with junk.

What do you think of the following options:

  • Option 1: enable the translation based on the Object Class, for instance I would enable it on DataObject\Folder, PrintingTechnique and PrintingOption but not on PrintingColor because there are 1893 Pantones in this folder that do not need to be translated.
  • Option 2: add a boolean property in the Class General Settings panel (we could name translatable keys)
  • Option 3: yours maybe?

Happy holidays and happy coding