plug_preferred_locales v0.1.0 PlugPreferredLocales

PlugPreferredLocales is a plug to parse the "accept-language" header and store a list of preferred locales in the :private key of the %Plug.Conn{}.

Options

The following options are supported:

  • :ignore_area - Determines wether to ignore the area part of a locale. This would cause the preferred locale en-US to be listed solely as en.

Link to this section Summary

Functions

Parses the accept header (if exists)

Parses a language range

Link to this section Types

Link to this type quality()
quality() :: {String.t(), Float.t()}

Link to this section Functions

Link to this function parse_accept_header(list)
parse_accept_header([String.t()]) :: [String.t()]

Parses the accept header (if exists).

It returns a list of language tags ordered by the quality factor.

Link to this function parse_language_range(language_range)
parse_language_range(String.t()) :: quality() | nil

Parses a language range.

Returns a tuple with the language tag as the first element and the quality as the second. If no quality is specified it uses 1.0.