Is it possible to generate dynamix translations with gettext?

In my module, we do a huge flow that involves an communication with an external api. I want to get their error messages and save them in database, but already translated to be able to send to the front end.

I get those errors in a rescue expression, as I can’t know all possible successful matches and then I pattern match only those error exceptions I want to deal with:

case err do
        %MatchError{term: err} ->
          error_msg = parse_error_message(err)

          :ok = FinanciamentosCancelados.clicksign_error(cancellation_id, error_msg)

          {:error, err}

        %File.Error{reason: err} ->
          error_msg = parse_error_message(err)

          :ok = FinanciamentosCancelados.internal_error(cancellation_id, error_msg)

          {:error, err}

        _ ->
          {:error, err}
      end

these are the possible errors i can get:

  # Clicksign errors
  defp parse_error_message({:error, :no_response}),
    do: %{api: dgettext("errors", "No response from Clicksign server")}

  defp parse_error_message({:error, :server}),
    do: %{api: dgettext("errors", "Clicksign's server internal error")}

  defp parse_error_message({:error, :not_found}),
    do: %{api: dgettext("errors", "Document not found")}

  defp parse_error_message({:error, :bad_request}),
    do: %{api: dgettext("errors", "Bad request")}

  defp parse_error_message({:error, :invalid_access_token}),
    do: %{api: dgettext("errors", "Invalid Clicksign access token")}

  defp parse_error_message({:error, :unauthorized_access_token}),
    do: %{api: dgettext("errors", "Unauthorized Clicksign access token")}

  defp parse_error_message({:error, :contract_already_finished}),
    do: %{api: dgettext("errors", "Clicksign Contract already finished")}

  defp parse_error_message({:error, :contract_unfinished}),
    do: %{api: dgettext("errors", "Clicksign Contract unfinished")}

  defp parse_error_message({:error, :contract_with_no_signs}),
    do: %{api: dgettext("errors", "Clicksign Contract with no signs")}

  defp parse_error_message({:error, %Ecto.Changeset{} = changeset}) do
    changeset_module = changeset.data
    module_source = :source  |> changeset_module.__schema__() |> String.to_existing_atom()

    errors = translate_errors(changeset)

    Map.put(%{}, module_source, errors)
  end

  defp parse_error_message({:error, reason}), do: humanize(reason)

however, this approach seems to not work…is like that the function parse_error_message returns nothing and the execution stops here. What am I doing wrong?

What do you mean by “stops here”?