Idiom.PluralAST (idiom v0.5.0)
Preprocessor for language-specific pluralization rules.
Idiom uses Unicode CLDR plural rules, which they provide for download as a JSON file. This is stored in our priv
directory.
The Plural
and PluralAST
modules use these definitions to generate Elixir ASTs representing a cond
statement for each language, which are then
used at compile-time to generate functions.
This module builds on a lexer and parser inside the src/
directory to generate the ASTs.
Summary
Functions
Parses a list of plural rules and converts them into a :cond
expression, with the clauses sorted by plural suffix.
Functions
Link to this function
parse_rules(rules)
Parses a list of plural rules and converts them into a :cond
expression, with the clauses sorted by plural suffix.
Examples
iex> Idiom.PluralAST.parse_rules([{"pluralRule-count-one", "n = 1"}])
{:cond, [], [[do: [{:->, [], [[{:==, [], [{:n, [], nil}, 1]}], "one"]}]]]}