boudra/alternate

Default language

Closed this issue · 0 comments

I wanted to make english to be default language:

config :polygot,
  locales: %{
    "en" => %{ path_prefix: "" },
    "pl" => %{ path_prefix: "pl" }
  },

It doesn't work. So i modified Polygot.Plug to use language with empty prefix when there is no prefix in route.

defmodule Polygot.Plug do

  #

  def call(conn, _opts) do

    {locale, _} = Enum.find @locales, fn item ->
      {locale, %{path_prefix: prefix}} = item
      prefix == ""
    end

    Gettext.put_locale(@gettext, locale)
    conn |> assign(:locale, locale)
  end

end

It works well in my very small (almost static) app, but I don't know if it's a good solution