PhoenixKitCatalogue.Catalogue.Translations (PhoenixKitCatalogue v0.1.14)

Copy Markdown View Source

Multilang data JSONB helpers — read merged language data from a record and write language-specific overrides through the entity's own update function.

Public surface is re-exported from PhoenixKitCatalogue.Catalogue.

Summary

Functions

Gets translated field data for a record in a specific language. Returns merged data (primary language as base + overrides for the requested language).

Updates the multilang data field for a record with language-specific field data. For primary language: stores ALL fields. For secondary languages: stores only overrides (differences from primary).

Functions

get_translation(record, lang_code)

@spec get_translation(map(), String.t()) :: map()

Gets translated field data for a record in a specific language. Returns merged data (primary language as base + overrides for the requested language).

set_translation(record, lang_code, field_data, update_fn, opts \\ [])

@spec set_translation(map(), String.t(), map(), function(), keyword()) ::
  {:ok, term()} | {:error, term()}

Updates the multilang data field for a record with language-specific field data. For primary language: stores ALL fields. For secondary languages: stores only overrides (differences from primary).

update_fn is the entity's update function. It receives (record, attrs) for 2-arity or (record, attrs, opts) for 3-arity when activity-logging opts are provided.