volto icon indicating copy to clipboard operation
volto copied to clipboard

Support translations for nonContentRoutes

Open teekuningas opened this issue 2 years ago • 0 comments

Using multilingual works fine for content-like routes that are easily separated into language root folders, such as /en/help or /fi/apua. However, it seems not so easy to have translated versions of non-content routes, maybe lying in a path like /a-little-game-thing-perhaps. Is there a proper solution to this?

The solution I ended up using was to customize the LanguageSwitcher so that it checks if the current route is in settings.nonContentRoutes, and if yes, it creates links that just change the I18N_LANGUAGE and refresh. It would have been all fine, but I also needed to patch @plone/volto/src/server.jsx to not force the default language on every request. In:

https://github.com/plone/volto/blob/master/src/server.jsx#L239

Changed this:

      if (cookie_lang !== contentLang) {

To:

if (cookie_lang !== contentLang && !config.settings.nonContentRoutes.includes(req.originalUrl)) {

After this, everything seems fine. I would not like to patch it though. Is there a more proper solution to this or should we have something like this at least in a form of not requiring any patching? Hope to hear your thoughts about this.

-- Teekoo

teekuningas avatar Jun 27 '22 07:06 teekuningas