# `Localize.Inflection.Quantify`
[🔗](https://github.com/elixir-localize/localize/blob/v1.4.0/lib/localize/inflection/quantify.ex#L1)

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.

# `quantify`

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

* `locale` is a locale atom or string; it selects the language's
  quantification rules.

* `number` is an integer, a float or a `Decimal`.

* `concept` is a `Localize.Inflection.Concept`.

* `options` is a keyword list of options.

### Options

* `:plural` is the CLDR plural category of the number; when absent
  it is selected from `number` by 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"}

# `quantify_formatted`

Quantifies a concept with a pre-formatted number.

### Arguments

* `locale` is 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_number` is the formatted number as a speakable
  string (binary or `{print, speak}`).

* `concept` is a `Localize.Inflection.Concept`.

* `options` is a keyword list of options.

### Options

* `:plural` is the CLDR plural category of the number; when
  absent it is selected by Localize's plural rules from the
  `:number` option.

* `:number` is 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 часа"}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
