Locale Names v1.0.1 Locale View Source

Utilities for working with locales (in the form of en-US).

The main goal is to be able to display a list of languages in their own spelling (en-US is “American English”, fr-CA is “Français canadien”).

The Locale struct

The fields are:

  • direction - In what direction is that language written
  • english_name - The English name of this language
  • locale_code - The locale code of this Locale
  • name - The name of that language in its own spelling

Link to this section Summary

Functions

Returns a tuple {:ok, locale()} where locale() is a Locale struct detailing the locale from the locale code passed or a tuple {:error, :locale_not_found}

Returns true if the locale code is supported, false otherwise

Link to this section Types

Link to this type direction_type() View Source
direction_type() :: :left_to_right | :right_to_left | :unknown_direction
Link to this type locale() View Source
locale() :: %Locale{
  direction: direction_type(),
  english_name: String.t(),
  locale_code: locale_code(),
  name: String.t()
}
Link to this type locale_code() View Source
locale_code() :: String.t()

Link to this section Functions

Link to this function locale(locale_code) View Source
locale(locale_code()) :: {:ok, locale()} | {:error, :locale_not_found}

Returns a tuple {:ok, locale()} where locale() is a Locale struct detailing the locale from the locale code passed or a tuple {:error, :locale_not_found}

Examples

iex> Locale.locale("en-US")
{:ok,
  %Locale{
    direction: :left_to_right,
    english_name: "American English",
    locale_code: "en-US",
    name: "American English"
  }
}

iex> Locale.locale("fr-FR")
{:ok,
  %Locale{
    direction: :left_to_right,
    english_name: "French",
    locale_code: "fr-FR",
    name: "Français"
  }
}
Link to this function locale?(locale_code) View Source
locale?(locale_code()) :: boolean()

Returns true if the locale code is supported, false otherwise.

Examples

iex> Locale.locale?("en-US")
true

iex> Locale.locale?("not-a-locale")
false