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?
I solved this using following method:
- I put my strings in
web/nuxeo.war/ui/i18n/messages.json
of thejar
bundle - I use this
deployment-fragment.xml
inOSGI-INF
of thejar
:<?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>
- The jar bundle is installed using the
update
scripting command ininstall.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
.
messages[-lang].json
intowindow.nuxeo.I18n[language]
, usingJSON.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.
deployment-fragment.xml
's append command is absolutely capable of merging json files - so it's actually possible to create the package with thedeployment-fragment.xml
in itsOSGI-INF
, and have it merged automatically at installation.