Localize.Inflection.SpeakableString (Localize v1.4.0)

Copy Markdown View Source

A string with an optional distinct spoken form.

Most values are plain binaries where the printed and spoken forms agree. When they differ (for example "boss’" printed but "boss’s" spoken) the value is {print, speak}.

Summary

Functions

Concatenates two speakable strings.

Builds a speakable string, collapsing to a binary when both forms agree.

Returns the printed form.

Returns the spoken form.

Types

t()

@type t() :: binary() | {binary(), binary()}

Functions

concat(left, right)

Concatenates two speakable strings.

Arguments

  • left is a speakable string.

  • right is a speakable string.

Returns

  • The concatenated speakable string, collapsed to a binary when the printed and spoken forms agree.

  • {:error, exception} if either argument is not a speakable string.

Examples

iex> Localize.Inflection.SpeakableString.concat("the ", "cat")
"the cat"

iex> Localize.Inflection.SpeakableString.concat({"boss’", "boss’s"}, " office")
{"boss’ office", "boss’s office"}

new(print, speak)

Builds a speakable string, collapsing to a binary when both forms agree.

Arguments

  • print is the printed form.

  • speak is the spoken form, or nil when it equals the printed form.

Returns

  • A speakable string.

Examples

iex> Localize.Inflection.SpeakableString.new("cat", "cat")
"cat"

iex> Localize.Inflection.SpeakableString.new("den", "dén")
{"den", "dén"}

print(speakable)

Returns the printed form.

Arguments

  • speakable is a speakable string.

Returns

  • The printed form as a binary.

  • {:error, exception} if speakable is not a speakable string.

Examples

iex> Localize.Inflection.SpeakableString.print("den")
"den"

iex> Localize.Inflection.SpeakableString.print({"den", "dén"})
"den"

speak(speakable)

Returns the spoken form.

Arguments

  • speakable is a speakable string.

Returns

  • The spoken form as a binary; the printed form when no distinct spoken form exists.

  • {:error, exception} if speakable is not a speakable string.

Examples

iex> Localize.Inflection.SpeakableString.speak("den")
"den"

iex> Localize.Inflection.SpeakableString.speak({"den", "dén"})
"dén"