Localize.Plug.AcceptLanguage (Localize Web v0.2.0)

Copy Markdown View Source

Standalone plug that parses the Accept-Language header and sets conn.private[:localize_locale] to the best matching locale.

The locale can be later retrieved by Localize.Plug.AcceptLanguage.get_locale/1. This plug is useful when you only need accept-language parsing without the full locale discovery pipeline of Localize.Plug.PutLocale.

Options

  • :no_match_log_level determines the logging level for the case when no matching locale is configured to meet the user's request. The default is :warning. If set to nil then no logging is performed.

Examples

plug Localize.Plug.AcceptLanguage

Summary

Functions

Returns the best matching locale for the provided accept-language header value.

Returns the locale set by Localize.Plug.AcceptLanguage.

Functions

best_match(accept_language, options)

Returns the best matching locale for the provided accept-language header value.

Arguments

  • accept_language is an accept-language header string or nil.

  • options is the plug options map containing :log_level.

Returns

get_locale(conn)

Returns the locale set by Localize.Plug.AcceptLanguage.

Arguments

Returns