wlminimal
Internationalization: Not working "post" method with set_locale package?
Hi all.
I want to be my website works in 2 locales (en , ko)
so I followed this tutorial
I installed set_locala package
and it will look like this.
in router.ex
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug SetLocale, gettext: TextingWeb.Gettext, default_locale: "ko", cookie_key: "project_locale"
end
scope "/:locale", TextingWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
# Sign in and out
get "/sign-in", AuthController, :new, as: :sign_in
post "/sign-in", AuthController, :new, as: :sign_in
get "/sign-out", AuthController, :delete, as: :sign_out
get "/sign-in/:token", AuthController, :create, as: :sign_in
get "/sign-up", UserController, :new, as: :sign_up
post "/sign-up", UserController, :create, as: :sign_up
get "/confirm-email", ConfirmEmailController, :new
post "/confirm-email", ConfirmEmailController, :create
end
It works ok, It displays other locale (Korean), but when I tried to sign-in, it doesn’t work.
params that I submited from sign-in form ignored,
[debug] Processing with TextingWeb.AuthController.new/2
Parameters: %{"locale" => "ko"}
Pipelines: [:browser]
It only returns %{“locale” => “ko”}
how can I work around this?
Marked As Solved
OvermindDL1
Ah, in that case it looks like that library has a bug:
https://github.com/smeevil/set_locale/blob/master/lib/set_locale.ex#L42
It appears it only supports converting GET requests, as it will turn any missing locale parameter into a redirected get request, unsure why it does that, seems like it would be better to just inject the locale string into the parameter list of the current request so downstream can pretend it is on the argument list.
Although based on what it’s doing it looks like it could just be replaced by a fairly simple GetText language setting plug inline with the router.
Also Liked
wlminimal
Popular in Questions
Other popular 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
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









