# `Hakushi.Messages`
[🔗](https://github.com/hattoriai/hakushi/blob/v0.1.0/lib/hakushi/messages.ex#L1)

The words of the canvas: the labels of its controls, the reasons it
gives when it refuses a change, and the announcements for screen
readers.

The words in your nodes are yours (translate them as the rest of your
app, with Gettext). The canvas's own words are here, in English,
Portuguese, Spanish, French, German and Japanese; a locale with a region (`pt-BR`, `en-GB`) takes the words of
its language, and another language gets English.

Give the palette other words with `messages`, a map from the keys of
`keys/0` to the new words, for example your own Gettext translations:

    <Hakushi.Components.canvas id="board" graph={@graph} messages={%{"fit" => gettext("Show all")}} />

Or set them for every canvas in the config:

    config :hakushi, messages: %{"fr" => %{"fit" => "Tout voir"}}

A word may have placeholders in braces (`{n}`, `{name}`), which the
canvas fills. The keys that end in `One` and `Other` are the plural
forms of a count, picked with the plural rules of the locale.

# `for_locale`

```elixir
@spec for_locale(String.t(), map()) :: %{required(String.t()) =&gt; String.t()}
```

The words for a locale: the built-in words of its language, then the
words of the config for the locale and for its language, then
`overrides`. Every key has a value (English when a language lacks one).

Raises `ArgumentError` for an override with an unknown key, so that a
typo shows.

## Examples

    iex> Hakushi.Messages.for_locale("pt-PT")["fit"]
    "Ver tudo"
    iex> Hakushi.Messages.for_locale("sv")["fit"]
    "Fit to screen"
    iex> Hakushi.Messages.for_locale("en", %{"fit" => "Show all"})["fit"]
    "Show all"

# `keys`

```elixir
@spec keys() :: [String.t()]
```

Returns the keys of the messages.

## Examples

    iex> "fit" in Hakushi.Messages.keys()
    true

# `language`

```elixir
@spec language(String.t()) :: String.t()
```

The language of a locale: `"pt"` for `"pt-BR"`, `"zh"` for `"zh_Hant"`.

## Examples

    iex> Hakushi.Messages.language("pt-BR")
    "pt"

# `languages`

```elixir
@spec languages() :: [String.t()]
```

Returns the languages with built-in words.

## Examples

    iex> Hakushi.Messages.languages()
    ["de", "en", "es", "fr", "ja", "pt"]

# `reason`

```elixir
@spec reason(map(), atom() | String.t()) :: String.t()
```

The words for a reason the canvas refused a change: a reason of
`Hakushi.Graph.apply/2` or `Hakushi.Rules.check/3` (an atom), or the
app's own words (a string) as they are.

## Examples

    iex> Hakushi.Messages.reason(Hakushi.Messages.for_locale("en"), :loop)
    "A node cannot connect to itself."
    iex> Hakushi.Messages.reason(%{}, "Only one owner.")
    "Only one owner."

---

*Consult [api-reference.md](api-reference.md) for complete listing*
