Declares, once per Ash domain, how its action errors are translated.
defmodule MyApp.Shop do
use Ash.Domain, extensions: [AshGettext.Domain]
gettext do
backend MyApp.Gettext
default_locale "en"
text_domain "ash"
locale_resolver MyApp.Locale
end
resources do
resource MyApp.Shop.Order
end
endConfiguration lives here rather than in config.exs on purpose. Ash configures
through DSL and passes request-scoped data through action context; global
application env would be process-wide mutable state, which forces
Application.put_env in tests and rules out async: true. Everything here is
read back through AshGettext.Info.
The supported locale list is deliberately not an option — it is derived from
the backend via AshGettext.known_locales/1, so it cannot drift from the
catalogs actually on disk.
Repeating this block across many domains is avoided the same way Ash avoids it
elsewhere: put it in a base domain macro and use that instead.
gettext
Configure how the errors of this domain's actions are translated.
Examples
gettext do
backend MyApp.Gettext
default_locale "en"
text_domain "ash"
end
Options
| Name | Type | Default | Docs |
|---|---|---|---|
backend | atom | The Gettext backend whose catalogs this domain translates against. | |
locale_resolver | module | Required. A module implementing AshGettext.Locale.Resolver. It reads the language from the action's actor. With no actor, Gettext's current process language is used. | |
default_locale | String.t | "en" | The locale used when the resolver names a language the catalogs do not have. |
text_domain | String.t | "ash" | The gettext text domain for everything Ash-derived: errors, enum labels, attribute names. |
translate_errors? | boolean | true | Whether resources in this domain translate their action errors. |
require_resource_extension? | boolean | false | When true, compiling the domain reports every resource in its resources block that lacks the AshGettext.Resource extension (a compiler warning, an error under --warnings-as-errors). Off by default on purpose: Ash extensions are opted into, never imposed. |