I was recently asked how one can manage vocabulary localization in-app instead of using i18n files deployed as part of the configuration. To my surprise it has actually been possible since the version 6.0. This feature went so unnoticed that almost nobody knows about it (at least I avoided the shame of being the only one at Nuxeo not knowing about it! ).
Vocabularies are lookup tables that you can use with suggestion widgets in the Nuxeo Platform.
Each entry typically consists of a key and a label. But of course if you have users who speak different languages, you may want the labels to be localized for each language. Since it’s definitely not cool having to update the configuration just to add/change an entry and its translations, the Nuxeo Content Services Platform lets you do that directly in-app and also provides an API Endpoint for it. But first you need to configure the vocabulary.
In the end a vocabulary is just another name for the more generic abstraction called Directory. The first thing we need in order to configure a new directory is a schema which contains one property for each language we want to support. Here we’ll use English, French, Spanish and German.
<xs:schema targetnamespace="http://www.nuxeo.org/ecm/schemas/customl10nxvocabulary" xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema>
Note that the same schema can be reused for multiple vocabularies. Next we can declare our directory with the corresponding extension point.
Just with that, we can already use the Directory API Endpoint to get, add, update, or delete entries in our new customl10ncoverage directory. Was fairly easy right?
Nuxeo API playground
Moreover the vocabulary is also available for use with the suggestion widget in the UI. We can see below that the labels are localized when we change the user locale.
Suggestion widget with localized labels (English)
Suggestion widget with localized labels (German)
The configuration of the widget with Nuxeo Studio couldn’t be easier. We only need to use the suggestOneDirectory widget with a string property, set the vocabulary name (with a custom property) and make sure that we set the localize and Activate database localization properties to true.
Widget Editor in Nuxeo Studio
Let’s go further and make the vocabulary manageable from the Admin Center. In order to do that we need to define a layout for and register it.
Vocabulary Editor in the Admin Center
Finally, nothing is set in stone and you can absolutely add new languages later just by updating the schema and the Admin Center layout. The full source of this example is in our github repository.