# `Localize.Message.Ecto.Type`
[🔗](https://github.com/elixir-localize/localize_sql/blob/v2.0.0/lib/localize/message/ecto/type.ex#L1)

An `Ecto.Type` storing an MF2 message, validated when it is written, in a text column.

A message an application keeps as data, such as a translation a site's editors write, is checked when it is cast and when it is dumped: it must be valid MF2 syntax and satisfy TR35's data-model rules, so a `.match` with no `*` variant or a variable declared twice is refused by the changeset rather than found when a visitor's page renders.

The value is the message's source as written, a string, so a form shows and edits it as it is. To format it many times, parse it once with `Localize.Message.parse/2` and format the result.

### Schema

    # in a migration
    add :greeting, :text

    # in a schema
    field :greeting, Localize.Message.Ecto.Type

### Casting

`cast/1` accepts a message string or a `t:Localize.Message.Parsed.t/0`, whose source is taken. A message that is not valid returns the error `"is not a valid MF2 message: %{detail}"`, with what is wrong in `:detail`. The message is a fixed msgid, so an application's `translate_error/1` can translate it, with `detail` as a binding.

### Loading

`load/1` returns the stored text as it is, without validating it, since Ecto raises when a value cannot be loaded and a row written before the column held validated messages must still be readable. Validate a loaded message with `Localize.Message.parse/2` where that matters.

# `embed_as`

# `equal?`

---

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