How to extend nuxeo.war/ui/i18n/messages.json?

nuxeo-wopi addon does not declare any package dependencies. However, it obviously depends on nuxeo-web-ui, since the latter includes the strings used for tooltips: wopiLink.* in i18n/messages.json, that ends up in nuxeo.war/ui. These tooltips are generated also in that package: see _wopiTooltip.

This raises the question, when I want to prepare a simple addon atop of the nuxeo-wopi (so my addon depends on it), how do I provide more strings to the nuxeo.war/ui/i18n/messages.json? My package does not include any jar packages, and only adds some icons to ${env.home}/nuxeo.war/ui/images, and a config to ${env.config}, using copy scripting command.

But there seems to be no scripting command to extend existing json files; adding another json file to that directory is ignored by nuxeo; and manually editing the json gets overwritten on server restart.

What is the correct way to add some strings to nuxeo.war/ui/i18n/messages.json when installing a simple addon?

0 votes

1 answers

95 views

ANSWER

The i18n in nuxeo-web-ui is implemented in nuxeo-elements/ui/nuxeo-i18n-behavior.js. It reads the hard-coded messages[-lang].json into window.nuxeo.I18n[language], using JSON.parse.

This does not allow extensions to add to the i18n json. It seems useful to have some list of json names to read, so that each would be parsed, and the results would be concatenated using javascript's spread syntax, like in this tutorial.

10/28/2020

Seems deployment-fragment.xml's append command is absolutely capable of merging json files - so it's actually possible to create the package with the deployment-fragment.xml in its OSGI-INF, and have it merged automatically at installation.
10/29/2020



I solved this using following method:

  1. I put my strings in web/nuxeo.war/ui/i18n/messages.json of the jar bundle
  2. I use this deployment-fragment.xml in OSGI-INF of the jar:
    <?xml version="1.0"?>
    <fragment version="1">
    <require>org.nuxeo.web.ui</require>
    <install>
    <delete path="${bundle.fileName}.tmp"/>
    <unzip from="${bundle.fileName}" to="${bundle.fileName}.tmp" prefix="web">
      <include>web/nuxeo.war/**</include>
    </unzip>
    <append from="${bundle.fileName}.tmp/nuxeo.war/ui/i18n/messages.json" to="nuxeo.war/ui/i18n/messages.json"/>
    <delete path="${bundle.fileName}.tmp"/>
    </install>
    </fragment>
    
  3. The jar bundle is installed using the update scripting command in install.xml of the addon package:
    <update file="${package.root}/install/bundles" todir="${env.bundles}" />
    

When I have localized strings, I will add relevant messages-lang.json to web/nuxeo.war/ui/i18n/, and append more append commands to the deployment-fragment.xml.

0 votes