MichaelKohler / activate-rewrite

Rewrite of activate.mozilla.community
https://rewrite.michaelkohler.info/
Mozilla Public License 2.0
1 stars 1 forks source link

Allow language links #12

Closed MichaelKohler closed 6 years ago

MichaelKohler commented 6 years ago

We should allow language links such as /en-US/subsite or /es/subsite which then directly switch the language to the requested language. If the language is not available, it should fall back to EN.

MichaelKohler commented 6 years ago

I'm facing a few challenges here, still learning my way around React architecture. :) Let me list the initial requirements here first:

Language links itself

I thought I can can use optional parameters to take the language in the URL or not.

<Route path='/:lng?/activities' component={ActivitiesPage}/>

This works well for /en-US/activities, but does not render the activity page (but the index page) for /activities. :( One way to solve this that I've found is to duplicate the routes, but that's not really something I want to do if there are better ways..

Updating the language according to URL language

If we get the above to work, we should update the language for Fluent depending on the URL lang param. I'd be tempted to use Redux for the state and dispatch a "LANGUAGE_CHANGE" action for this (as well as use that when the user manually switches the language). However, where would I dispatch it for the URL? The Router would render every component, and I'm not keen to dispatch this in every single component. Any thoughts would be appreciated :)

Setting links to url prefix on the page

If the user chooses de-DE or comes in via /de/ all the links on the page should be prefixed with /de. The ReactRouter basename is not dynamic, so that's not an option. Another option would be to read out the current language from the store and prefix it on every link. Not particularly ideal either. Are there better ways?

Manually switching the language

If the user manually switches the language, the URL should probably be rewrittten. That one is probably a normal URL rewrite which should not be too hard. Need to check this out.

Any thoughts on this would be greatly appreciated :)

MichaelKohler commented 6 years ago

PR: https://github.com/MichaelKohler/activate-rewrite/pull/31

MichaelKohler commented 6 years ago

The manual language switching is now living in https://github.com/MichaelKohler/activate-rewrite/issues/32