Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translatable paths #64

Open
klis87 opened this issue Sep 27, 2019 · 2 comments
Open

Translatable paths #64

klis87 opened this issue Sep 27, 2019 · 2 comments

Comments

@klis87
Copy link

klis87 commented Sep 27, 2019

Hi, I am heavy user of redux first router and cannot wait for this library to become stable and documented.

In the meantime, I am wondering whether you will support better a case from RFR issue I posted some time ago faceyspacey/redux-first-router#94

Ideally it would be great if all translation logic could be encapsulated in a route configuration, so we would not need to worry about going from /en/home to /de/haus and vice versa, as home/haus could be calculated by this library based on and option/basename

then, /en/haus and /de/home would raise 404, and swithing basename when on /en/home from en to de would automatically recalculate url to /de/haus

@hedgepigdaniel
Copy link
Collaborator

Sure, It would be nice to support that if it can be done in a simple way.

I would probably start by writing some code that preprocesses a routesMap to get the behaviour you want (or as close as possible) and trying to find the minimum change that would support it in the router itself. I wonder if you can:

  • somehow make the path regex a huge OR with a separate inner regex for each language (not sure if its possible to put parameters inside regexes, or if a regex is only allowed to be itself a single param?)
  • match all the options for all the languages in the path regex, and then filter out, translate, or redirect invalid mixtures of languages in a custom Rudy middleware? I imagine this middleware would sit immediately before transformAction in the default middleware pipeline (to fix up languages before the serialized URL is added to the action)
  • autogenerate a separate route (action type + URL regex) for each language (in addition to a general action for all languages that the rest of your code sees), and then have rudy middlewares that redirect a general action on the way in (from a redux dispatch) to the appropriate language, and then redirect it back to the general action type on the way out (including if it originates from a page load or URL change)

Check out some of the simple examples for middlewares (e.g. the set page title package). There's alot of flexibility there over what was possible in RFR and the middleware API is they key to it. Also check out the toPath/fromPath options and such, they work a little differently.

Let me know if you need any help - I know documentation is sparse but I'm happy to point you in the right direction :)

@klis87
Copy link
Author

klis87 commented Oct 4, 2019

Thx for detailed answer. When I have some time, I will to switch from RFR to Rudy and I will post the outcome how I solved multilang urls, I also agree that it would be best to use existing Rudy Api for this purposes, or with minimum adjustments, if not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants