It has to be done on compilation to merge the shared-ui message bundle with an other app's message bundle. The resulting message bundle can be passed in the gadget xml file for a specific locale

<Locale lang="en" messages="i18n/en/message-bundle.xml" />

We have a script for authoring ui that combines all the message bundles into one file per lang. It's available here: https://vcs.websys.tmcs/svn/jetson/authoring/ui/shared-authoring-ui/trunk/src/main/resources/script/bundle-messages.js

It's a rhino script. It's not mandatory to use this, but we could provide it in shared-ui if you think it would be useful for other people.