# `Localize.LanguageTag.Ecto.Type`
[🔗](https://github.com/elixir-localize/localize_sql/blob/v1.0.1/lib/localize/language_tag/ecto/type.ex#L1)

An `Ecto.Type` storing a locale as its BCP 47 string in a text column.

A `t:Localize.LanguageTag.t/0` is a rich struct — resolved likely
subtags, `-u-` extension keywords, a canonical form — but all of it is
derived from the language tag string, so the string is what is stored.
The column is ordinary text holding a canonical tag such as `"en-US"`
or `"de-DE-u-co-phonebk"`.

Values load back into a fully resolved `t:Localize.LanguageTag.t/0` via
`Localize.validate_locale/1`, so a loaded locale is canonicalized, has
its `-u-` extensions populated and its likely subtags resolved — the
same value `Localize.validate_locale/1` returns anywhere else, and the
resolution is cached.

### Schema

    # in a migration
    add :locale, :string

    # in a schema
    field :locale, Localize.LanguageTag.Ecto.Type

### Casting

`cast/1` accepts a `t:Localize.LanguageTag.t/0`, or any locale
identifier `Localize.validate_locale/1` accepts — a string (`"en-US"`)
or an atom (`:"en-US"`). An identifier that is not a valid locale
returns an error rather than being stored.

# `embed_as`

# `equal?`

---

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