AshPhoenixTranslations.Info (ash_phoenix_translations v1.0.0)

View Source

Introspection module for AshPhoenixTranslations extension.

Provides functions to retrieve translation configuration and metadata from resources that use the AshPhoenixTranslations extension.

Examples

Assuming you have a resource with translations configured:

defmodule MyApp.Product do
  use Ash.Resource,
    extensions: [AshPhoenixTranslations]

  translations do
    translatable_attribute :name, locales: [:en, :es, :fr]
    translatable_attribute :description, locales: [:en, :es, :fr]
    backend :database
    cache_ttl 7200
  end
end

You can introspect the configuration:

iex> AshPhoenixTranslations.Info.translatable?(MyApp.Product)
true

iex> AshPhoenixTranslations.Info.supported_locales(MyApp.Product)
[:en, :es, :fr]

iex> AshPhoenixTranslations.Info.backend(MyApp.Product)
:database

iex> AshPhoenixTranslations.Info.cache_ttl(MyApp.Product)
7200

Summary

Functions

Returns the all translations calculation name for an attribute.

Get the approval policy for a resource.

Returns whether translation changes should be audited.

Returns whether translations should be automatically validated.

Returns the configured backend for translations.

Returns the cache TTL in seconds.

Get the edit policy for a resource.

Returns the translation storage field name for an attribute.

Returns all supported locales across all translatable attributes.

Returns whether a resource has any translatable attributes.

Returns a specific translatable attribute by name.

Returns all translatable attributes for a resource.

Get the translation policy configuration for a resource.

translations DSL entities

Whether to audit translation changes

Whether to audit translation changes

Whether to automatically validate required translations

Whether to automatically validate required translations

The backend to use for storing translations (database or gettext)

The backend to use for storing translations (database or gettext)

The Gettext module to use (e.g., MyAppWeb.Gettext). Required when backend is :gettext

The Gettext module to use (e.g., MyAppWeb.Gettext). Required when backend is :gettext

translations DSL options

Policy configuration for translation access control

Policy configuration for translation access control

Get the view policy for a resource.

Functions

all_translations_field(attribute_name)

@spec all_translations_field(atom()) :: atom()

Returns the all translations calculation name for an attribute.

approval_policy(resource)

@spec approval_policy(Ash.Resource.t() | Spark.Dsl.t()) :: keyword() | nil

Get the approval policy for a resource.

audit_changes?(resource)

@spec audit_changes?(Ash.Resource.t() | Spark.Dsl.t()) :: boolean()

Returns whether translation changes should be audited.

auto_validate?(resource)

@spec auto_validate?(Ash.Resource.t() | Spark.Dsl.t()) :: boolean()

Returns whether translations should be automatically validated.

backend(resource)

@spec backend(Ash.Resource.t() | Spark.Dsl.t()) :: :database | :gettext

Returns the configured backend for translations.

cache_ttl(resource)

@spec cache_ttl(Ash.Resource.t() | Spark.Dsl.t()) :: pos_integer()

Returns the cache TTL in seconds.

edit_policy(resource)

@spec edit_policy(Ash.Resource.t() | Spark.Dsl.t()) :: atom() | tuple() | nil

Get the edit policy for a resource.

storage_field(attribute_name)

@spec storage_field(atom()) :: atom()

Returns the translation storage field name for an attribute.

supported_locales(resource)

@spec supported_locales(Ash.Resource.t() | Spark.Dsl.t()) :: [atom()]

Returns all supported locales across all translatable attributes.

translatable?(resource)

@spec translatable?(Ash.Resource.t() | Spark.Dsl.t()) :: boolean()

Returns whether a resource has any translatable attributes.

translatable_attribute(resource, name)

@spec translatable_attribute(Ash.Resource.t() | Spark.Dsl.t(), atom()) ::
  AshPhoenixTranslations.TranslatableAttribute.t() | nil

Returns a specific translatable attribute by name.

translatable_attributes(resource)

@spec translatable_attributes(Ash.Resource.t() | Spark.Dsl.t()) :: [
  AshPhoenixTranslations.TranslatableAttribute.t()
]

Returns all translatable attributes for a resource.

translation_policies(resource)

@spec translation_policies(Ash.Resource.t() | Spark.Dsl.t()) :: keyword() | nil

Get the translation policy configuration for a resource.

translations(dsl_or_extended)

@spec translations(dsl_or_extended :: module() | map()) :: [struct()]

translations DSL entities

translations_audit_changes(dsl_or_extended)

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

Whether to audit translation changes

translations_audit_changes!(dsl_or_extended)

@spec translations_audit_changes!(dsl_or_extended :: module() | map()) ::
  boolean() | no_return()

Whether to audit translation changes

translations_auto_validate(dsl_or_extended)

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

Whether to automatically validate required translations

translations_auto_validate!(dsl_or_extended)

@spec translations_auto_validate!(dsl_or_extended :: module() | map()) ::
  boolean() | no_return()

Whether to automatically validate required translations

translations_backend(dsl_or_extended)

@spec translations_backend(dsl_or_extended :: module() | map()) ::
  {:ok, :gettext | :database} | :error

The backend to use for storing translations (database or gettext)

translations_backend!(dsl_or_extended)

@spec translations_backend!(dsl_or_extended :: module() | map()) ::
  (:gettext | :database) | no_return()

The backend to use for storing translations (database or gettext)

translations_cache_ttl(dsl_or_extended)

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

Cache TTL in seconds

translations_cache_ttl!(dsl_or_extended)

@spec translations_cache_ttl!(dsl_or_extended :: module() | map()) ::
  pos_integer() | no_return()

Cache TTL in seconds

translations_gettext_module(dsl_or_extended)

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

The Gettext module to use (e.g., MyAppWeb.Gettext). Required when backend is :gettext

translations_gettext_module!(dsl_or_extended)

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

The Gettext module to use (e.g., MyAppWeb.Gettext). Required when backend is :gettext

translations_options(dsl_or_extended)

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

translations DSL options

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

translations_policy(dsl_or_extended)

@spec translations_policy(dsl_or_extended :: module() | map()) ::
  {:ok,
   approval: [required_for: [atom()], approvers: [atom()]],
   edit: (:translator | :admin) | {atom(), [atom()]} | atom(),
   view:
     (:translator | :admin | :authenticated | :public)
     | {atom(), keyword()}
     | atom()}
  | :error

Policy configuration for translation access control

translations_policy!(dsl_or_extended)

@spec translations_policy!(dsl_or_extended :: module() | map()) ::
  [
    approval: [required_for: [atom()], approvers: [atom()]],
    edit: (:translator | :admin) | {atom(), [atom()]} | atom(),
    view:
      (:translator | :admin | :authenticated | :public)
      | {atom(), keyword()}
      | atom()
  ]
  | no_return()

Policy configuration for translation access control

view_policy(resource)

@spec view_policy(Ash.Resource.t() | Spark.Dsl.t()) :: atom() | tuple() | nil

Get the view policy for a resource.