Quantified noun phrases: a number joined with a noun that agrees with it grammatically.
This is the port of the upstream CommonConceptFactory quantify
feature. The plural category drives a number constraint on the
concept (singular, dual or plural where the language has them),
per-language rules adjust the grammatical case (Slavic numeral
government, the Arabic counted-noun cases), and a per-language
join places the number, noun and any measure word (CJK
classifiers, Thai).
The number arrives pre-formatted and the plural category is resolved through Localize's own plural rules (or supplied per call): number formatting and plural selection remain with the caller, which for Localize means its own formatting and plural rules.
Summary
Functions
Quantifies a concept with a number, writing the number as the language writes the number of a quantity.
Quantifies a concept with a pre-formatted number.
Functions
Quantifies a concept with a number, writing the number as the language writes the number of a quantity.
The number is written in the locale's digits. Where the language's
numbers agree with the noun (in gender, and in case in German,
Finnish and the Slavic languages), its spoken form is the words that
agree; Hebrew and Italian write the smallest numbers as words. The
result is then joined as quantify_formatted/4 joins it.
Arguments
localeis a locale atom or string; it selects the language's quantification rules.numberis an integer, a float or aDecimal.conceptis aLocalize.Inflection.Concept.optionsis a keyword list of options.
Options
:pluralis the CLDR plural category of the number; when absent it is selected fromnumberby Localize's plural rules.
Returns
{:ok, speakable}with the quantified phrase, or{:error, reason}.
Examples
iex> {:ok, concept} = Localize.Inflection.Concept.new(:es, "niña")
iex> Localize.Inflection.Quantify.quantify(:es, 1, concept)
{:ok, {"1 niña", "una niña"}}
iex> {:ok, concept} = Localize.Inflection.Concept.new(:en, "kilometer")
iex> Localize.Inflection.Quantify.quantify(:en, 2, concept)
{:ok, "2 kilometers"}
Quantifies a concept with a pre-formatted number.
Arguments
localeis a locale atom or string; it selects the language's quantification rules and may be more specific than the concept's locale (:"zh-HK"selects the Cantonese classifier join).formatted_numberis the formatted number as a speakable string (binary or{print, speak}).conceptis aLocalize.Inflection.Concept.optionsis a keyword list of options.
Options
:pluralis the CLDR plural category of the number; when absent it is selected by Localize's plural rules from the:numberoption.:numberis the numeric value, used to resolve the plural category via the provider and, for Serbo-Croatian, to detect fractions (which take the genitive singular).
Returns
{:ok, speakable}with the quantified phrase, or{:error, reason}.
Examples
iex> {:ok, concept} = Localize.Inflection.Concept.new(:en, "kilometer")
iex> Localize.Inflection.Quantify.quantify_formatted(:en, "2", concept, plural: :other)
{:ok, "2 kilometers"}
iex> {:ok, concept} = Localize.Inflection.Concept.new(:ru, "час")
iex> Localize.Inflection.Quantify.quantify_formatted(:ru, "2", concept, plural: :few)
{:ok, "2 часа"}