Multilingual.RedirectIncoming (multilingual v0.1.3)

Redirects incoming requests to the user's preferred language.

Use this plug in your router pipeline to redirect incoming requests to the user's preferred language, as indicated by the "Accept-Language" header.

This plug should be preceded by another plug that actually does the fetching and parsing of the "Accept-Language" header, such as Cldr.Plug.AcceptLanguage.

Two options are required:

  • :accept_locale_source - the module that provides the user's preferred language. Currently, only Cldr is supported,
  • :nearest_known - a function that returns the nearest known locale to the user's preferred locale.

Example

pipeline :browser do
  ...
  plug Cldr.Plug.AcceptLanguage, cldr_backend: MyApp.Cldr
  plug RedirectIncoming,
    accept_locale_source: Cldr,
    nearest_known: &MyApp.nearest_known/1
  ...
end

Summary

Functions

If a request has a "Referer" that is not the current host, we may want to redirect to the user's preferred language, as indicated by the "Accept-Language" header.

Functions

Link to this function

call(conn, opts)

If a request has a "Referer" that is not the current host, we may want to redirect to the user's preferred language, as indicated by the "Accept-Language" header.

Link to this function

nearest_known(locale, redirect_incoming)