Skip to content

getLocaleEraNames

getLocaleEraNames(locale: string, style?: LocaleNameStyle): string[]
import { getLocaleEraNames } from "@northguild/gmt/plain/locale";

Return a locale’s Gregorian era names as [BCE-label, CE-label].

  • The two-element array is [Before Common Era label, Common Era label].
  • Uses the host runtime’s Intl data via Intl.DateTimeFormat, so output depends on the runtime’s ICU build (full-ICU runtimes localize every locale; partial-ICU runtimes fall back to English).
  • If a locale has no distinct BCE/CE era names, both array elements contain the same string — the function never returns a sentinel for a valid locale, only for invalid input.
  • Returns [] if locale is not a valid BCP 47 tag.
Parameter Type Description
locale string BCP 47 locale tag (e.g. “en-US”, “fr-FR”, “ar-SA”)
style LocaleNameStyle Optional name style: "long" (default), "short", or "narrow"

2-element [BCE-label, CE-label] array, or [] on invalid input

getLocaleEraNames("en-US") // ["Before Christ", "Anno Domini"]
getLocaleEraNames("de-DE", "short") // ["v. Chr.", "n. Chr."]
getLocaleEraNames("ja-JP", "narrow") // ["BC", "AD"]
getLocaleEraNames("not-a-locale") // []

plain/locale/getLocaleEraNames.ts