PhoenixLocale
Locale functions to be integrated into Phoenix providing a plug and view helpers
PhoenixLocalePlug checks if there's a :locale param on the requested route, if there is and matches the existing locales, puts the locale on the session. If there isn't a :locale defined, PhoenixLocalePlug puts the default locale on the session. If the requested :locale does not exist, puts the default locale on the session. PhoenixLocale.Helpers are a couple of view helpers that can be used on templates to help determine user's preferred locale.
You can see the online documentation for more information.
Requirements
Elixir 1.4.2
Phoenix 1.2.1
Instructions
Define your I18n Module on config.ex
config :phoenix_locale, PhoenixLocale,
i18n: MyApp.I18nIf you want a 404 error when no available local is found just need to configure as:
config :phoenix_locale, PhoenixLocale,
i18n: MyApp.I18n, raise_no_available_locale: true
Add PhoenixLocale.Plug to the plug list on your routes file, on the browser pipeline after Phoenix plugs
pipeline :browser do
plug :accepts, ~w(html)
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug PhoenixLocale.Plug
end
If you need to use the helper functions, add PhoenixLocale.Helpers to your web module:
def view do
quote do
use Phoenix.View, root: "web/templates"
import MyAPP.Router.Helpers
use Phoenix.HTML
import PhoenixLocale.Helpers
end
end
Check the online documentation for the list of helpers available