View Source Expo.PluralForms (expo v0.1.0-beta.3)
Gettext Plural Helper
https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html
Link to this section Summary
Functions
Compile plural forms so that it returns the index
Convert parsed plural form to string
Get Index from PluralForms Header
Parse Plural Forms Header
Parse Plural Forms Header
Get Plural Forms for language
Link to this section Types
@type parse_error() :: {:error, {:parse_error, message :: String.t(), line :: pos_integer(), offset :: pos_integer()}}
@type t() :: {nplurals :: pos_integer(), plural :: plural()}
Link to this section Functions
Compile plural forms so that it returns the index
bindings
Bindings
n
- the number to get the index for
usage
Usage
defmodule MyModule do
{:ok, {2, plurals}} = Expo.PluralForms.parse_string("nplurals=2; plural=n>1;")
def index(n), do: unquote(Expo.PluralForms.compile_index(plurals))
end
Convert parsed plural form to string
@spec index(plural_forms :: plural(), n :: non_neg_integer()) :: non_neg_integer()
Get Index from PluralForms Header
examples
Examples
iex> {:ok, {2, plurals}} = Expo.PluralForms.parse_string("nplurals=2; plural=n != 1;")
iex> Expo.PluralForms.index(plurals, 4)
1
Parse Plural Forms Header
Works exactly like parse_string/1
, but returns a plural forms tuple
if there are no errors or raises a Expo.PluralForms.SyntaxError
error
if there are.
examples
Examples
iex> Expo.PluralForms.parse_string!("nplurals=2; plural=n != 1;")
{2, {:!=, :n, 1}}
iex> Expo.PluralForms.parse_string!("invalid")
** (Expo.PluralForms.SyntaxError) 1:0 expected string "nplurals="
@spec parse_string(content :: String.t()) :: {:ok, t()} | parse_error()
Parse Plural Forms Header
examples
Examples
iex> Expo.PluralForms.parse_string("nplurals=2; plural=n != 1;")
{:ok, {2, {:!=, :n, 1}}}
Get Plural Forms for language
examples
Examples
iex> Expo.PluralForms.plural_form("de")
{:ok, {2, {:paren, {:!=, :n, 1}}}}
iex> Expo.PluralForms.plural_form("invalid")
:error