Idiom.PluralPreprocess (idiom v0.1.1)
Preprocessor for language-specific pluralization rules.
Summary
Functions
Parses and sorts language-specific pluralization rules.
Functions
parse_rules(arg)
Parses and sorts language-specific pluralization rules.
This function takes as input a tuple, where the first element is a string representing the language identifier (e.g., "en"
for English), and the second element is a list of tuples. Each tuple in the list represents a pluralization rule, with the first element being a string that specifies the rule's category (e.g., "pluralRule-count-one"
), and the second element being a string that specifies the rule itself.
The function parses these rules into abstract syntax trees (ASTs), sorts them according to a predefined order ("zero", "one", "two", "few", "many", "other"), and returns a tuple where the first element is the language identifier and the second element is the AST of a cond
statement with a clause for each rule and suffix.
Examples
iex> Idiom.PluralPreprocess.parse_rules({"en", [{"pluralRule-count-one", "n = 1"}]})
{"en", {:cond, [], [[do: [{:->, [], [[{:==, [], [{:n, [], nil}, 1]}], "one"]}]]]}}