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?

1 Like

Can you link to the set_locala library?

I believe this is the set_locale library the OP is referring to (linked from the tutorial):

Ah, in that case it looks like that library has a bug:

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.

Oh, Thanks, I really appreciate that.

1 Like