Gettext

Fluxon UI supports translating Phoenix validation error messages. You can configure a translation function to handle validation errors from form components using Gettext or custom translation logic.

Configuration

To enable error translation, configure a translation function in your application config:

# config/config.exs
config :fluxon, :translate_function, &MyAppWeb.CoreComponents.translate_error/1

Phoenix with Gettext

If you're using Phoenix with Gettext, the translation function is typically located in your CoreComponents module:

# lib/my_app_web/components/core_components.ex
defmodule MyAppWeb.CoreComponents do
  def translate_error({msg, opts}) do
    if count = opts[:count] do
      Gettext.dngettext(MyAppWeb.Gettext, "errors", msg, msg, count, opts)
    else
      Gettext.dgettext(MyAppWeb.Gettext, "errors", msg, opts)
    end
  end
end

Then configure Fluxon to use it:

# config/config.exs
config :fluxon, :translate_function, &MyAppWeb.CoreComponents.translate_error/1

That's it! All Fluxon form components will automatically use your configured translation function to translate validation error messages.