Kanta.Translations.Messages (kanta v0.5.1)

Kanta Messages subcontext

Summary

Functions

create_message(attrs, opts \\ [])

delete_message(message_id)

Deletes a stale message and ALL its translations across ALL locales.

This function removes the message completely from the system, including all singular and plural translations in every locale.

Arguments

  • message_id - Integer ID of the message

Returns

  • {:ok, stats} - Map containing deletion statistics:
    • :translations_deleted - Number of translations deleted across all locales
    • :message_deleted - Boolean indicating if message was deleted
  • {:error, reason} - If deletion fails

Examples

iex> Kanta.Translations.Messages.delete_message(123)
{:ok, %{translations_deleted: 5, message_deleted: true}}

delete_messages(message_ids)

get_message(params \\ [])

get_messages_count()

list_all_messages(params \\ [])

list_messages(params \\ [])

merge_messages(from_message_id, to_message_id)

Merges two messages by moving all translations from one message to another.

This operation:

  1. Deletes all existing translations from the target message
  2. Moves all translations from the source message to the target message
  3. Deletes the source message

This is useful when a stale message needs to be merged with its replacement (e.g., when msgid changes due to typo fixes or wording changes).

Arguments

  • from_message_id - ID of the source message (will be deleted)
  • to_message_id - ID of the target message (will receive translations)

Returns

  • {:ok, target_message} - Target message with merged translations
  • {:error, :not_found} - One or both messages not found
  • {:error, reason} - Merge failed

Examples

iex> merge_messages(123, 456)
{:ok, %Message{id: 456, ...}}

update_message(message, attrs)