<commit_before>defmodule JumubaseWeb.ErrorHelpers do
  @moduledoc """
  Conveniences for translating and building error messages.
  """

  use Phoenix.HTML
  alias Ecto.Changeset

  @doc """
  Generates tag for inlined form input errors.
  """
  def error_tag(form, field) do
    Enum.map(Keyword.get_values(form.errors, field), fn error ->
      content_tag(:small, translate_error(error), class: "help-block")
    end)
  end

  def error_list_tag(errors) do
    content_tag :ul do
      for error <- errors do
        content_tag(:li, translate_error(error))
      end
    end
  end

  @doc """
  Traverses the changeset's errors and translates them.
  """
  def get_translated_errors(%Changeset{} = cs) do
    Changeset.traverse_errors(cs, &translate_error/1)
  end

  # Private helpers

  # Translates an error message using gettext.
  defp translate_error({msg, opts}) do
    # Because error messages were defined within Ecto, we must
    # call the Gettext module passing our Gettext backend. We
    # also use the "errors" domain as translations are placed
    # in the errors.po file.
    # Ecto will pass the :count keyword if the error message is
    # meant to be pluralized.
    # On your own code and templates, depending on whether you<commit_msg>Update error helper as per LiveView documentation<commit_after>defmodule JumubaseWeb.ErrorHelpers do
  @moduledoc """
  Conveniences for translating and building error messages.
  """

  use Phoenix.HTML
  alias Ecto.Changeset

  @doc """
  Generates tag for inlined form input errors.
  """
  def error_tag(form, field) do
    form.errors
    |> Keyword.get_values(field)
    |> Enum.map(fn error ->
      content_tag(:small, translate_error(error), class: "help-block")
    end)
  end

  def error_list_tag(errors) do
    content_tag :ul do
      for error <- errors do
        content_tag(:li, translate_error(error))
      end
    end
  end

  @doc """
  Traverses the changeset's errors and translates them.
  """
  def get_translated_errors(%Changeset{} = cs) do
    Changeset.traverse_errors(cs, &translate_error/1)
  end

  # Private helpers

  # Translates an error message using gettext.
  defp translate_error({msg, opts}) do
    # Because error messages were defined within Ecto, we must
    # call the Gettext module passing our Gettext backend. We
    # also use the "errors" domain as translations are placed
    # in the errors.po file.
    # Ecto will pass the :count keyword if the error message is
    # meant to be pluralized.
    # On your own code and templates, depending on whether you
{'fraction_non_alphanumeric': 0.08093385214007782, 'fraction_numerical': 0.0007782101167315176, 'mean_word_length': 3.292153589315526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '126763', 'n_tokens_mistral': 788, 'n_tokens_neox': 760, 'n_words': 275}