gampleman/elm-translate-icu/1.0.0

Icu.Ast

The abstract syntax tree for an ICU MessageFormat message.

A parsed message is a list of Parts. This module is the shared representation that a parser produces and that a formatter or code generator consumes — it deliberately mirrors the structure of the ICU syntax.

type alias Message =
List Part

A message is an ordered sequence of parts. Rendering the message means rendering each part in turn and concatenating the results.

type Part
= Literal String
| Argument String
| Number String (Maybe String)
| Date String (Maybe String)
| Time String (Maybe String)
| Select String (List ( String, Message )) Message
| Plural
{ arg : String
, ordinal : Bool
, offset : Int
, forms : List PluralForm
, other : Message
}
| Pound

A single piece of a message.

  • Literal — raw text, e.g. Hello. ICU quoting ('', '{') is resolved by the parser, so a Literal holds the already-unescaped text.
  • Argument — a bare placeholder {name}.
  • Number / Date / Time — a typed placeholder such as {n, number} or {d, date, long}, with an optional style/skeleton string.
  • Select — {g, select, ...}, a plain keyword switch with a mandatory other branch.
  • Plural — {n, plural, ...} or {n, selectordinal, ...}. ordinal distinguishes the two; offset carries offset:N.
  • Pound — the # placeholder inside a plural branch, replaced by the (offset-adjusted) argument value.
type alias PluralForm =
( PluralSelector, Message )

One branch of a plural / selectordinal block, e.g. one {...} or =0 {...}.

= Exact Int
| Keyword String

Selects which plural branch applies: either an exact literal match (=0, =1, ...) or a CLDR plural keyword (zero, one, two, few, many). The other branch is stored separately on Part.Plural.

argumentNames : Message -> List String

Collect every argument name referenced anywhere in a message, including those nested inside select and plural branches. Order of first appearance is preserved and duplicates are removed.