# `mix verified_translations.migrate`
[🔗](https://github.com/treathealth/verified_translations/blob/v0.1.1/lib/mix/tasks/verified_translations.migrate.ex#L66)

Migrates gettext calls and PO translations to ~t

Rewrites `gettext/1,2` (and `dgettext/2,3` with the `"default"` domain)
in Elixir code, `~H` templates and `.heex` files into `~t`, moves their
translations from `priv/gettext/*/LC_MESSAGES/default.po` into
`priv/translations/default/*.json` and removes the migrated messages
from the PO and POT files.

    gettext("Hello %{name}", name: @user.name)
    # becomes
    ~t"Hello #{@user.name}"
    # msgid "Hello %{user_name}", placeholders in translations renamed to match

`ngettext/3,4` becomes `tn/2` with its PO plural forms mapped to CLDR
categories:

    ngettext("1 file", "%{count} files", length(files))
    # becomes
    tn(length(files), one: "1 file", other: "%{count} files")

Bindings that are not a variable, assign or field keep their Gettext name:
`gettext("Hi %{name}", name: String.upcase(u))` becomes
`~t"Hi #{name = String.upcase(u)}"`.

Projects using `gettext_sigils` get `use GettextSigils` replaced and the
dependency removed. Their `~t` sigils produce the same msgids, so
`mix verified_translations.extract` imports the existing translations.

Domains and contexts become `~t` modifiers (`dgettext("errors", "x")` ->
`~t"x"e`), defined in the `use VerifiedTranslations` that gives the module
`~t`; plural ones become `tn(n, domain: "errors", ...)`.

Calls that cannot be expressed are left alone and listed: dynamic msgids,
and domains or contexts without a `use VerifiedTranslations` to define a
modifier in.

Only modules that can use `~t` are rewritten (`use VerifiedTranslations`
or `use MyAppWeb, ...`). Run with `--dry-run` to review the diff.

## Example

```sh
mix verified_translations.migrate --locales en,fi,sv
```

## Options

* `--locales` - comma separated locales, source locale first. Defaults to
  `en` plus the locale directories in `priv/gettext`.
* `--gettext` - Gettext priv directory, default `priv/gettext`
* `--path` - translations directory, default `priv/translations`

---

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