Course contentsShow
← JavaScript
Lesson 2244 of 2,72346. InternationalizationFree lesson

DisplayNames for Calendar and Date Fields

Access localized names for calendar types and date-time field labels.

DisplayNames for Calendar and Date Fields

You'll learn how to retrieve human-readable, localized names for calendar systems and date-time field labels using Intl.DisplayNames.

What This Solves

When building internationalized applications, you often need to display the names of date-time components—like "month," "year," or "timezone"—in the user's language. Rather than hardcoding translations, Intl.DisplayNames with the calendar and dateTimeField types provides these labels automatically.

Core Idea

The Intl.DisplayNames API supports two additional types beyond languages, regions, currencies, and scripts:

  • calendar: Returns the localized name of a calendar system (e.g., "Gregorian", "Buddhist", "Islamic").
  • dateTimeField: Returns the localized name of date-time components (e.g., "month", "year", "hour", "weekday").

Think of it like asking a multilingual assistant: "What do people in Japan call the 'Gregorian calendar' in their language?" Instead of maintaining translation tables, the browser knows.

Using Calendar and DateTimeField Types

// Get calendar names in German
const calendarNames = new Intl.DisplayNames(['de'], { type: 'calendar' });
console.log(calendarNames.of('gregory')); // "Gregorianischer Kalender"
console.log(calendarNames.of('buddhist')); // "Buddhistischer Kalender"

// Get date field names in French
const fieldNames = new Intl.DisplayNames(['fr'], { type: 'dateTimeField' });
console.log(fieldNames.of('year'));    // "année"
console.log(fieldNames.of('month'));   // "mois"
console.log(fieldNames.of('weekday')); // "jour de la semaine"
console.log(fieldNames.of('hour'));    // "heure"

This is particularly useful for building custom date pickers, calendar widgets, or settings interfaces where users select date components.

Key Takeaway: Use Intl.DisplayNames with type: 'calendar' or type: 'dateTimeField' to access localized names for calendar systems and date-time field labels, eliminating the need for manual translation tables.