inveniosoftware / cookiecutter-invenio-rdm

Cookiecutter template for a new InvenioRDM instance.
MIT License
4 stars 33 forks source link

Add support for overriding translations (message catalogs) #199

Open lnielsen opened 2 years ago

lnielsen commented 2 years ago

We should add support so the default messages (text labels etc) could be overwritten in case an instance wants to use different text.

This could be achieve by adding a translations directory with message catalogs.

/translations
/translations/en
/translations/en/messages.po
/translations/en/messages.mo  

Invenio-CLI would need to symlink and compile the catalog into the Flask instance folder to be picked up: https://github.com/inveniosoftware/invenio-i18n/blob/master/invenio_i18n/ext.py#L101-L110

Probably it should also support extra messages from local templates.

To be seen how this plays with domains etc.

lnielsen commented 2 years ago

Also, this should take the React part into account. Suggestion from Zoe on the chat was to use https://github.com/i18next/i18next-chained-backend

zguillen commented 2 years ago

guys - I stabbed at this problem from all sorts of angles and failed to find an easy way for the RDM app to override translations defined in modules that get installed into it's node_modules. I ended up bailing on this task tho :( we needed other UI customizations to react-invenio-deposit beyond changing just the words so we needed to fork and modify the repo anyways. Where I ended up though was with 2 options, 1. let the RDM app expose it's overwritten translations files via an api endpoint and then the react-invenio- modules can use that endpoint as a ‘chained backend’, or 2. Do some webpack magic to react-invenio- modules so that overriding translations works sort of like how less vars get overridden. It seems like there should already be a webpack plugin for this sort of thing but I failed to find it. Something like this craco one I used years back that let me customize antd’s less vars by adding it to my webpack config and then creating the antd.customize.less file in my react app that had antd in it's node_modules: https://github.com/DocSpring/craco-antd but maybe that’s way overkill...