szsoppa
Global default url parameters based on conn values
Hi guys!
I’m using set_locale for language handling. My client requested to have locale included in the path instead of parameters. So instead of:
Example Domain we should have: example.com/pl
Furthermore, for the default locale, the path SHOULD NOT include locale, but instead, it should be assigned via cookies. Assuming that default locale is en, instead of:
example.com/en it should be example.com
With a bit of modification in set_locale I was able to set the root path for default locale without including it in the path. There is however a problem here. I need to include @locale in every path helper (routes are scoped in /:locale) across the entire app. For default locale, I don’t want to include it in the path since it’s one of the client requests.
So the question is - Is there any way to pass default params to path generators globally? In Rails, I’m able to achieve that with the default_url_options method in Controller. Such a default URL option in my case depends on @conn assigns which is probably problematic.
First Post!
LostKobrakai
I’d normalize that outside of the router, a.k.a. in the endpoint remove the leading path segment if it’s a locale and for url helpers use a function to scope them to locales like conn |> maybe_prepend_locale() |> Routes.page_path(:index). Path helpers do work when supplied a %URI{} struct, so that’s what maybe_prepend_locale would likely return.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









