Flicker.Messages behaviour (Flicker v0.1.0)

Copy Markdown View Source

The behaviour every user-facing Flicker string routes through (ADR-009).

Every visible string and every screen-reader announcement the select component renders comes from message/2 — never an inline literal in a template. Flicker.Messages.English is the complete default implementation and doubles as the canonical list of every message key.

Overriding

A host can override messages globally:

config :flicker, messages: MyAppWeb.FlickerMessages

or per-component, via the messages attr on Flicker.select/1. An override module needs only implement the keys it wants to change — delegate the rest to Flicker.Messages.English:

defmodule MyAppWeb.FlickerMessages do
  @behaviour Flicker.Messages

  @impl true
  def message(:search_placeholder, _bindings), do: "Rechercher..."
  def message(key, bindings), do: Flicker.Messages.English.message(key, bindings)
end

Message keys are public API once shipped — renaming one is a breaking change.

Summary

Types

Named values interpolated into a message (e.g. %{count: 5}).

A message key. See Flicker.Messages.English for the full list.

Callbacks

Returns the user-facing string for key, interpolating bindings.

Functions

Looks up key through the resolved messages module, falling back to Flicker.Messages.English if the resolved module doesn't implement that key — so a partial override module can never crash a render.

Resolves the effective messages module for a component instance.

Types

bindings()

@type bindings() :: map()

Named values interpolated into a message (e.g. %{count: 5}).

key()

@type key() :: atom()

A message key. See Flicker.Messages.English for the full list.

Callbacks

message(key, bindings)

@callback message(key(), bindings()) :: String.t()

Returns the user-facing string for key, interpolating bindings.

Functions

get(component_messages \\ nil, key, bindings \\ %{})

@spec get(module() | nil, key(), bindings()) :: String.t()

Looks up key through the resolved messages module, falling back to Flicker.Messages.English if the resolved module doesn't implement that key — so a partial override module can never crash a render.

resolve(component_messages \\ nil)

@spec resolve(module() | nil) :: module()

Resolves the effective messages module for a component instance.

Precedence: the per-component messages attr override, then config :flicker, :messages, then Flicker.Messages.English.