mix ash.gen.gettext (ash v3.24.3)

Copy Markdown View Source

Copies Ash's .pot file into your application's priv/gettext/ directory.

This allows you to create locale-specific .po files for translating Ash error messages using the standard gettext workflow.

Usage

$ mix ash.gen.gettext
$ mix ash.gen.gettext --domain errors

Options

  • --domain / -d — Target gettext domain. Defaults to "ash".

    When set to a domain other than "ash" (e.g., "errors"), Ash's translatable messages are merged into the existing priv/gettext/<domain>.pot file. The Ash entries are placed after a marker comment and replaced on each run, making this operation idempotent. Multiple libraries (e.g., ash, ash_authentication) can each maintain their own marked section in the same file.

    This is useful when your application already translates errors under the "errors" domain and you want Ash messages available there without changing your translate_error/1 code.

Workflow

Default (ash domain)

  1. Run mix ash.gen.gettext to copy ash.pot into your priv/gettext/.

  2. Run mix gettext.merge priv/gettext --locale ko to create priv/gettext/ko/LC_MESSAGES/ash.po.

  3. Fill in the msgstr values in the .po file.

  4. In your translate_error/1, call:

    Gettext.dgettext(MyApp.Gettext, "ash", msg, vars)

Custom domain (e.g., errors)

  1. Run mix ash.gen.gettext --domain errors to merge Ash messages into your existing priv/gettext/errors.pot.
  2. Run mix gettext.merge priv/gettext --locale ko as usual.
  3. Your existing translate_error/1 using dgettext(backend, "errors", ...) works without changes.