How do you display calendar names like Gregorian, Hebrew, Islamic?

Use JavaScript's Intl.DisplayNames API to show human-readable calendar system names in any language

Introduction

Different cultures and religions use different calendar systems to track dates and organize time. While the Gregorian calendar is common in many parts of the world, other calendar systems are used for religious observances, cultural events, and daily life. The Hebrew calendar is used in Israel and by Jewish communities worldwide. The Islamic calendar guides Muslim religious practices. The Buddhist calendar is used in Thailand and other Southeast Asian countries.

Applications that serve international audiences need to let users choose their preferred calendar system. Date pickers, settings interfaces, and scheduling tools display calendar names so users can select the system that matches their needs. Instead of showing cryptic codes like "gregory" or "islamic-umalqura", apps display readable names like "Gregorian Calendar" or "Umm al-Qura Calendar".

JavaScript's Intl.DisplayNames API converts calendar system codes into human-readable names. This API handles translations automatically, showing calendar names in the user's language without requiring manual translation files.

What are calendar codes

Calendar codes are short string identifiers that represent different calendar systems. JavaScript uses these standardized codes internally to identify calendars.

Common calendar codes include:

  • gregory for the Gregorian calendar
  • hebrew for the Hebrew calendar
  • islamic for the Islamic calendar
  • buddhist for the Buddhist calendar
  • chinese for the Chinese calendar
  • japanese for the Japanese calendar

These codes follow the Unicode locale identifier specification. They are always lowercase and use hyphens to separate words when needed, like islamic-umalqura or islamic-civil.

How Intl.DisplayNames works with calendars

The Intl.DisplayNames constructor creates an object that translates codes into readable text. You specify a locale for the output language and a type for the kind of codes you want to translate.

To display calendar names, you pass "calendar" as the type:

const displayNames = new Intl.DisplayNames('en', { type: 'calendar' });

The first argument is the locale code like 'en' for English or 'fr' for French. The second argument is an options object where you set type: 'calendar'.

Once you have a DisplayNames object, you use its of() method to convert calendar codes into names:

const calendarName = displayNames.of('gregory');
console.log(calendarName); // "Gregorian Calendar"

Display calendar names in English

Here is how you display the names of the Gregorian, Hebrew, and Islamic calendars in English:

const displayNames = new Intl.DisplayNames('en', { type: 'calendar' });

console.log(displayNames.of('gregory')); // "Gregorian Calendar"
console.log(displayNames.of('hebrew')); // "Hebrew Calendar"
console.log(displayNames.of('islamic')); // "Islamic Calendar"

You can display any supported calendar by passing its code to the of() method:

const displayNames = new Intl.DisplayNames('en', { type: 'calendar' });

console.log(displayNames.of('buddhist')); // "Buddhist Calendar"
console.log(displayNames.of('chinese')); // "Chinese Calendar"
console.log(displayNames.of('japanese')); // "Japanese Calendar"
console.log(displayNames.of('persian')); // "Persian Calendar"

The Islamic calendar has multiple variants for different calculation methods:

const displayNames = new Intl.DisplayNames('en', { type: 'calendar' });

console.log(displayNames.of('islamic')); // "Islamic Calendar"
console.log(displayNames.of('islamic-umalqura')); // "Umm al-Qura Calendar"
console.log(displayNames.of('islamic-civil')); // "Islamic Civil Calendar"
console.log(displayNames.of('islamic-tbla')); // "Islamic Tabular Calendar"

Get all available calendar systems

JavaScript provides 17 calendar systems. You can get the complete list programmatically using Intl.supportedValuesOf():

const calendars = Intl.supportedValuesOf('calendar');
console.log(calendars);

This returns an array of all supported calendar codes:

[
  'buddhist',
  'chinese',
  'coptic',
  'dangi',
  'ethioaa',
  'ethiopic',
  'gregory',
  'hebrew',
  'indian',
  'islamic',
  'islamic-umalqura',
  'islamic-tbla',
  'islamic-civil',
  'islamic-rgsa',
  'iso8601',
  'japanese',
  'persian',
  'roc'
]

You can iterate through this array to display all calendar names:

const calendars = Intl.supportedValuesOf('calendar');
const displayNames = new Intl.DisplayNames('en', { type: 'calendar' });

calendars.forEach(calendar => {
  console.log(`${calendar}: ${displayNames.of(calendar)}`);
});

This prints:

buddhist: Buddhist Calendar
chinese: Chinese Calendar
coptic: Coptic Calendar
dangi: Dangi Calendar
ethioaa: Ethiopic Amete Alem Calendar
ethiopic: Ethiopic Calendar
gregory: Gregorian Calendar
hebrew: Hebrew Calendar
indian: Indian National Calendar
islamic: Islamic Calendar
islamic-umalqura: Umm al-Qura Calendar
islamic-tbla: Islamic Tabular Calendar
islamic-civil: Islamic Civil Calendar
islamic-rgsa: Islamic Calendar (Saudi Arabia)
iso8601: ISO-8601 Calendar
japanese: Japanese Calendar
persian: Persian Calendar
roc: Minguo Calendar

Localize calendar names in different languages

Calendar names appear in the language you specify in the locale parameter. This lets you show calendar names to users in their preferred language.

Display calendar names in Arabic:

const displayNames = new Intl.DisplayNames('ar', { type: 'calendar' });

console.log(displayNames.of('gregory')); // "التقويم الميلادي"
console.log(displayNames.of('hebrew')); // "التقويم العبري"
console.log(displayNames.of('islamic')); // "التقويم الهجري"

Display calendar names in French:

const displayNames = new Intl.DisplayNames('fr', { type: 'calendar' });

console.log(displayNames.of('gregory')); // "calendrier grégorien"
console.log(displayNames.of('hebrew')); // "calendrier hébraïque"
console.log(displayNames.of('islamic')); // "calendrier musulman"

Display calendar names in Hebrew:

const displayNames = new Intl.DisplayNames('he', { type: 'calendar' });

console.log(displayNames.of('gregory')); // "לוח השנה הגרגוריאני"
console.log(displayNames.of('hebrew')); // "לוח השנה העברי"
console.log(displayNames.of('islamic')); // "לוח השנה ההיג'רי"

Display calendar names in Chinese:

const displayNames = new Intl.DisplayNames('zh', { type: 'calendar' });

console.log(displayNames.of('gregory')); // "公历"
console.log(displayNames.of('hebrew')); // "希伯来历"
console.log(displayNames.of('islamic')); // "伊斯兰历"

The browser handles all translations automatically. You do not need translation files or manual string management.

Build a calendar selector dropdown

Here is how you create a dropdown menu that lets users select a calendar system:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Calendar Selector</title>
</head>
<body>
  <label for="calendar-select">Choose a calendar:</label>
  <select id="calendar-select"></select>

  <script>
    const userLocale = navigator.language || 'en';
    const displayNames = new Intl.DisplayNames(userLocale, { type: 'calendar' });
    const calendars = Intl.supportedValuesOf('calendar');
    const selectElement = document.getElementById('calendar-select');

    calendars.forEach(calendar => {
      const option = document.createElement('option');
      option.value = calendar;
      option.textContent = displayNames.of(calendar);
      selectElement.appendChild(option);
    });

    selectElement.addEventListener('change', (event) => {
      console.log('Selected calendar:', event.target.value);
    });
  </script>
</body>
</html>

This code does the following:

  1. Gets the user's browser locale with navigator.language
  2. Creates a DisplayNames object with the user's locale
  3. Retrieves all available calendar codes
  4. Creates an option element for each calendar
  5. Sets the option text to the localized calendar name
  6. Adds an event listener to handle calendar selection

The dropdown automatically shows calendar names in the user's language. A user with an Arabic browser sees Arabic calendar names. A user with a French browser sees French calendar names.

When to use calendar name display

Display calendar names in these situations:

  • Settings pages where users choose their preferred calendar system
  • Date picker components that support multiple calendar systems
  • Event creation forms where users specify which calendar to use
  • User profile pages where calendar preference is stored
  • Scheduling applications that work across different calendar systems
  • Religious or cultural applications that reference specific calendars

Calendar name display makes your application accessible to users who work with non-Gregorian calendar systems. It removes ambiguity about which calendar system the application uses for dates and events.

The Intl.DisplayNames API with type: 'calendar' gives you instant access to localized calendar names without maintaining translation files or calendar system metadata.