alexbruf/elm-cally/1.1.0

Cally.Locale

Everything language- and region-specific that the pickers need.

Cally reaches for Intl.DateTimeFormat. Elm has no Intl, so a Locale is a plain record of formatting functions that you can build yourself. Two English locales ship with the package; both reproduce the exact strings node's ICU produces for en-GB and en-US (see upstream/intl-fixture.json), including the thin-space en-dash ICU uses between the two halves of a range.

type alias Locale =
{ dir : Dir
, firstDayOfWeek : Weekday
, monthName : MonthFormat -> Month -> String
, weekdayName : WeekdayFormat -> Weekday -> String
, dayLabel : Date -> String
, yearMonth : HeadingFormat -> YearMonth -> String
, yearMonthRange : HeadingFormat -> YearMonth -> YearMonth -> String
, weekLabel : String
, previousLabel : String
, nextLabel : String
, yearLabel : String
, monthLabel : String
}

Everything the pickers need to render text.

  • dir decides which way ArrowLeft and ArrowRight move.
  • firstDayOfWeek is the default for Config.firstDayOfWeek.
  • dayLabel is the aria-label of a day button, Cally's { month: "long", day: "numeric" }: "5 January" or "January 5".
  • yearMonth and yearMonthRange render the picker headings, Cally's format / formatVerbose and their formatRange.
  • the remaining *Label fields are the visually hidden and default texts.

Bundled locales

enGB : Locale

British English. Weeks start on Monday, day labels read "5 January", and September's short name is "Sept".

enUS : Locale

American English. Weeks start on Sunday and day labels read "January 5".

Supporting types

type Dir
= Ltr
| Rtl

Writing direction. Cally checks :dir(ltr) at runtime to decide which way the left and right arrow keys move; elm-cally reads this field instead.

type alias YearMonth =
{ year : Int
, month : Month
}

A year and a month, with no day. Mirrors Cally's PlainYearMonth.

type alias HeadingFormat =
{ year : Maybe YearFormat
, month : Maybe MonthFormat
}

The { year, month } half of Intl.DateTimeFormat's options. Nothing drops the field, exactly like leaving the option out.

= YearNumeric
| YearTwoDigit

How a year should be rendered: 2026 or 26.

= MonthLong
| MonthShort
| MonthNarrow
| MonthNumeric
| MonthTwoDigit

How a month should be rendered. Mirrors the month option of Intl.DateTimeFormat.

= WeekdayLong
| WeekdayShort
| WeekdayNarrow

How a weekday should be rendered. Mirrors the weekday option of Intl.DateTimeFormat.