# `AshGettext.Locale.Normalizer`
[🔗](https://github.com/Undeadlol1/ash_gettext/blob/v0.1.0/lib/ash_gettext/locale/normalizer.ex#L1)

Reduce a locale as it arrives in the wild to one the catalogs actually have.

Clients send `ru_RU`, `en-US`, `ru`, or nothing at all. Catalogs are keyed by
the language subtag. This module is the single place that reconciles the two,
so no call site has to decide what `en_KZ` means.

`AshGettext.Info.language/2` runs it on what the resolver returns.
It runs on every translated error, so it does no I/O and keeps no state.
A language the backend does not ship falls back to the default locale.

# `language_code`

```elixir
@spec language_code(String.t()) :: String.t()
```

Strip the region and script from `locale`, leaving the language subtag.

    iex> AshGettext.Locale.Normalizer.language_code("en-US")
    "en"

# `normalize`

```elixir
@spec normalize(String.t() | nil, [String.t()], String.t()) :: String.t()
```

Reduce `locale` to a supported locale, or `default` when it maps to none.

The region and script are dropped, so `"ru_RU"` and `"ru-Cyrl"` both become
`"ru"`. A `nil` locale returns `default`. The result is always a member of
`supported` or `default` itself.

    iex> AshGettext.Locale.Normalizer.normalize("ru_RU", ["en", "ru"], "en")
    "ru"

    iex> AshGettext.Locale.Normalizer.normalize("de", ["en", "ru"], "en")
    "en"

    iex> AshGettext.Locale.Normalizer.normalize(nil, ["en", "ru"], "en")
    "en"

---

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