AshGettext.Info (AshGettext v0.1.0)

Copy Markdown View Source

Read a domain's gettext do ... end configuration.

Spark.InfoGenerator supplies the per-option readers — gettext_backend/1, gettext_default_locale/1, gettext_text_domain/1, gettext_locale_resolver/1, gettext_translate_errors?/1 — each returning {:ok, value} or :error, plus raising ! variants.

On top of those, settings/1 answers the one question every caller actually has: is this domain set up to translate, and with what?

Summary

Types

Everything needed to translate for a domain.

Functions

The written label of a resource's attribute from its gettext block, or nil.

Every written attribute label of a resource, as {attribute, text}.

The Gettext backend whose catalogs this domain translates against.

The Gettext backend whose catalogs this domain translates against.

The locale used when the resolver names a language the catalogs do not have.

The locale used when the resolver names a language the catalogs do not have.

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.

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.

gettext DSL options

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.

The gettext text domain for everything Ash-derived: errors, enum labels, attribute names.

The gettext text domain for everything Ash-derived: errors, enum labels, attribute names.

Whether resources in this domain translate their action errors.

The {backend, locale} to use for actor, or nil for Gettext's current language.

The domain's gettext settings, whether or not error translation is on.

The domain's translation settings, or :error when it does not translate.

Types

settings()

@type settings() :: %{
  backend: module(),
  default_locale: String.t(),
  text_domain: String.t(),
  locale_resolver: module() | nil,
  supported_locales: [String.t()]
}

Everything needed to translate for a domain.

Functions

attribute_label(resource, attribute)

@spec attribute_label(module(), atom()) :: String.t() | nil

The written label of a resource's attribute from its gettext block, or nil.

attribute_labels(resource)

@spec attribute_labels(module()) :: [{atom(), String.t()}]

Every written attribute label of a resource, as {attribute, text}.

gettext_backend(dsl_or_extended)

@spec gettext_backend(dsl_or_extended :: module() | map()) :: {:ok, atom()} | :error

The Gettext backend whose catalogs this domain translates against.

gettext_backend!(dsl_or_extended)

@spec gettext_backend!(dsl_or_extended :: module() | map()) :: atom() | no_return()

The Gettext backend whose catalogs this domain translates against.

gettext_default_locale(dsl_or_extended)

@spec gettext_default_locale(dsl_or_extended :: module() | map()) ::
  {:ok, String.t()} | :error

The locale used when the resolver names a language the catalogs do not have.

gettext_default_locale!(dsl_or_extended)

@spec gettext_default_locale!(dsl_or_extended :: module() | map()) ::
  String.t() | no_return()

The locale used when the resolver names a language the catalogs do not have.

gettext_locale_resolver(dsl_or_extended)

@spec gettext_locale_resolver(dsl_or_extended :: module() | map()) ::
  {:ok, module()} | :error

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.

gettext_locale_resolver!(dsl_or_extended)

@spec gettext_locale_resolver!(dsl_or_extended :: module() | map()) ::
  module() | no_return()

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.

gettext_options(dsl_or_extended)

@spec gettext_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

gettext DSL options

Returns a map containing the and any configured or default values.

gettext_require_resource_extension?(dsl_or_extended)

@spec gettext_require_resource_extension?(dsl_or_extended :: module() | map()) ::
  boolean()

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.

gettext_text_domain(dsl_or_extended)

@spec gettext_text_domain(dsl_or_extended :: module() | map()) ::
  {:ok, String.t()} | :error

The gettext text domain for everything Ash-derived: errors, enum labels, attribute names.

gettext_text_domain!(dsl_or_extended)

@spec gettext_text_domain!(dsl_or_extended :: module() | map()) ::
  String.t() | no_return()

The gettext text domain for everything Ash-derived: errors, enum labels, attribute names.

gettext_translate_errors?(dsl_or_extended)

@spec gettext_translate_errors?(dsl_or_extended :: module() | map()) :: boolean()

Whether resources in this domain translate their action errors.

language(domain, actor)

@spec language(module() | map(), term()) :: {module(), String.t()} | nil

The {backend, locale} to use for actor, or nil for Gettext's current language.

Asks the domain's locale_resolver with the actor and fits the answer to the catalogs. nil when there is no actor or the resolver returns nil. Nothing here changes the process language.

locale_settings(domain)

@spec locale_settings(module() | map()) :: {:ok, settings()} | :error

The domain's gettext settings, whether or not error translation is on.

:error only when the domain has no gettext block. Used to find the backend, text domain and language rules for enums, attributes and the action's language.

settings(domain)

@spec settings(module() | map()) :: {:ok, settings()} | :error

The domain's translation settings, or :error when it does not translate.

Returns :error both for a domain without the AshGettext.Domain extension and for one that has explicitly set translate_errors? false, so a caller can treat "not configured" and "switched off" the same way — pass the value through untouched.