BartOtten / phoenix_localized_routes

Localize your Phoenix website with multilingual URLs and custom template assigns; enhancing user engagement and content relevance.
MIT License
22 stars 1 forks source link

Thoughts on this working with ~p routes #6

Open olivermt opened 2 years ago

olivermt commented 2 years ago

Hello,

Have you seen Chris' presentation on phoenix 1.7 and verified routes? Do you reckon this lib will be able to work seamlessly with that? Have you given it any thought?

BartOtten commented 2 years ago

Sorry for the late reply, did not get a notification. I will get to this soon, as RC1 has just been released today so the verified routes implementation is considered ‘done’.

BartOtten commented 1 year ago

Released a Release Candidate version you can try: https://elixirforum.com/t/phoenix-localized-routes-localized-multilingual-routes-in-phoenix/48486/22?u=bartotten

Please let me know if it works as expected.

olivermt commented 1 year ago

Tremendous! Will try this next week

BartOtten commented 1 year ago

Hi @olivermt,

Could you provide me a status report?

sfusato commented 1 year ago

I've encountered an issue when trying to use query params:

<.link href={~p"/users/register?#{[foo: "bar"]}"}>Register</.link>

<.link href={~p"/users/register?#{%{foo: "bar"}}"}>Register</.link>
  1. On the locale to which these routes belong, in this case the en locale, there are only compilation warnings: no route path matches that aren't there when switching to the ~o sigil (Phoenix's verified routes sigil basically).

  2. When you're switching to a different locale, there's an error thrown:

<.link href={~p"/users/register?#{[foo: "bar"]}"}>Register</.link>
Protocol.UndefinedError at GET /europe/be/producten
protocol Phoenix.Param not implemented for [foo: "bar"] of type List. This protocol is implemented for the following type(s): Any, Atom, BitString, Float, Integer, Map
<.link href={~p"/users/register?#{%{foo: "bar"}}"}>Register</.link>
ArgumentError at GET /europe/be/producten
maps cannot be converted to_param. A struct was expected, got: %{foo: "bar"}

Hard coding the params works:

<.link href={~p"/users/register?foo=bar"}>Register</.link>

but only on the hard coded locale route. It's not being copied to the other localized routes:

http://localhost:4000/users/register?foo=bar
http://localhost:4000/europe/be/gebruikers/registreren
http://localhost:4000/europe/nl/gebruikers/registreren
http://localhost:4000/gb/users/register

Expected:

http://localhost:4000/users/register?foo=bar
http://localhost:4000/europe/be/gebruikers/registreren?foo=bar
http://localhost:4000/europe/nl/gebruikers/registreren?foo=bar
http://localhost:4000/gb/users/register?foo=bar

Tested on the bo/phx1.7 branch of the example application.

BartOtten commented 1 year ago

Hi @sfusato and @olivermt,

The refactoring of Phoenix Localized Routes has lead to a more flexible lib: Routex. Please give it a try as I am eager to get some feedback before I "publish" the lib at Elixir forum.

Migration from Phoenix Localized Routes (PLR) to Routex Although I have not written a migration guide yet, it should be straightforward.

Links Hex: https://hex.pm/packages/routex Demo: https://routex.fly.dev/ Full diff adding Routex to the demo app: https://github.com/BartOtten/routex_example/commit/a1ca0d0f1fb411d33a15864cc765dbb39de428da

sfusato commented 1 year ago

@BartOtten Can you make the routex_example repository public?

BartOtten commented 1 year ago

My bad :)

sfusato commented 1 year ago

Thanks. I'm having a compilation error when adding routex to a new project (opened an issue in the project's repository). The other issue is with regards to a route not found in the example app (opened an issue in the routex_example repository).