# `mix localize.gettext.mf2`
[🔗](https://github.com/elixir-localize/localize/blob/v1.10.0/lib/mix/tasks/localize.gettext.mf2.ex#L1)

Converts an application's Gettext catalogs and the msgids of its `gettext` calls from Gettext's `%{name}` syntax to MF2, for a backend that uses `Localize.Gettext.Interpolation`.

Every `.pot` and `.po` file under the catalog directories is converted with `Localize.Gettext.Migration.convert/2`, and every `.ex`, `.exs` and `.heex` file under the source directories with `Localize.Gettext.Migration.convert_source/2`. Both apply the same conversion to a msgid, so a call and its catalog entry still match, and each converted message formats as the original did. Only the files that change are written; a catalog is written as `Expo.PO.compose/1` writes it.

### What is converted

A msgid is the key a translation is found by, so an entry is converted only where every lookup of it changes with it, and is otherwise left as it is, which the interpolator still reads:

* A call whose domain is an expression may look up any msgid of any domain, so no entry is converted, and the call is reported.

* A domain with a call whose msgid is an expression, as in a `translate_error/1` that translates Ecto's and Ash's messages in `errors`, keeps all its entries, and the call is reported. Where such a lookup only ever receives msgids written in calls in the converted source, as a `Gettext.gettext(MyApp.Gettext, label)` whose labels come from `gettext_noop("…")` does, name the domain with `--trust` to convert it. Never trust `errors`, whose msgids come from Ecto and Ash at runtime.

* Otherwise an entry is converted when every source file its `#:` references name lies under a `--source` directory, or, with no references, when a call there uses it. A catalog shared with another application, whose references name `../other_app/lib/page.ex`, keeps that application's entries unless its source is given too.

References are read relative to `--root`, the directory the catalogs were extracted in.

With `--plurals`, each plural entry that every catalog of its domain can write as one `.match` message, as `Localize.Gettext.Migration.convertible_plurals/2` tells, becomes a singular entry, and its `ngettext` calls become `gettext` calls with the count in their bindings. A catalog's language is its `Language` header, or else the directory above its `LC_MESSAGES`. A domain is a catalog's file name, and a call's domain its literal domain argument, or `--default-domain` for a call that names none. Run `mix format` afterwards.

Run it on a clean working tree, so the changes can be reviewed as a diff. A msgid the task cannot rewrite, one written as a sigil, a concatenation or an expression, is listed with its file and line for a person to convert.

### Usage

    mix localize.gettext.mf2 [--priv DIR]... [--source DIR]... [--root DIR] [--trust DOMAIN]... [--plurals] [--dry-run]

### Options

* `--priv` is a directory of catalogs, which may be given more than once. The default is `priv/gettext`.

* `--source` is a directory of source files, which may be given more than once. The default is `lib`.

* `--root` is the directory catalog references are relative to. The default is the current directory.

* `--trust` is a domain whose dynamic lookups receive only msgids written in calls in the converted source, which may be given more than once.

* `--plurals` converts plural entries and calls to `.match` messages.

* `--source-locale` is the language msgids are written in, for the plural rules of a converted msgid. The default is `en`.

* `--default-domain` is the domain of a call that names none. The default is `default`.

* `--dry-run` reports what would change without writing any file.

---

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