<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshGettext.Resource

Opts a resource into translated action errors, enum labels and attribute names.

    defmodule MyApp.Shop.Order do
      use Ash.Resource,
        domain: MyApp.Shop,
        extensions: [AshGettext.Resource]
    end

No attribute is rewritten and no enum is replaced; the `attributes do` block
stays as it is. The extension points each write action's `error_handler` at
the library, and adds one public calculation, `<attribute>_label`, for each
attribute whose type is an `AshGettext.Enum` (see
`AshGettext.Resource.Transformers.AddEnumLabels`). Load it to get the label
on the record: `Ash.get!(Order, id, load: [:status_label])`.

Attribute names are written by you, never made from the code name:

    gettext do
      label :delivery_date, "Delivery date"
    end

`AshGettext.attribute_label/2` translates that text. An attribute with no
`label` raises. A `label` for an attribute the resource lacks fails to compile.

Labels loaded on records and errors from actions use the language of the
action's actor, else Gettext's current language. No action changes the
process language.

What to translate is read from the resource's **domain** (`AshGettext.Domain`).
A resource whose domain does not configure `gettext`, or which sets
`translate_errors? false`, keeps its messages exactly as they are.

To avoid writing `extensions:` on every resource, put it in the base resource
macro the app almost certainly already has.


## gettext
The texts a person reads for this resource's attributes.

### Nested DSLs
 * [label](#gettext-label)


### Examples
```
gettext do
  label :delivery_date, "Delivery date"
end

```




### gettext.label
```elixir
label attribute, text
```


The text a person reads for an attribute. Written by you, then translated.



### Examples
```
label :delivery_date, "Delivery date"
```



### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`attribute`](#gettext-label-attribute){: #gettext-label-attribute .spark-required} | `atom` |  | The attribute the text names. |
| [`text`](#gettext-label-text){: #gettext-label-text .spark-required} | `String.t` |  | The text, in the source language. |











<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>
