JavaScript i18n (Intl.*): Formatting Dates, Numbers, and Text

JavaScript's Intl APIs let you format dates, numbers, currency, lists, text comparisons, and relative times in a way that matches a user's locale. This matters any time your app serves people in different regions, because formatting rules vary by language, country, and writing system.

Quick answer: Use the Intl namespace when you need locale-aware formatting in JavaScript. The most common tools are Intl.DateTimeFormat, Intl.NumberFormat, and Intl.Collator, plus convenience methods like toLocaleString().

Difficulty: Beginner

You'll understand this better if you know: basic JavaScript objects, how dates and numbers are represented, and how function options objects work.

1. What Is JavaScript i18n (Intl.*)?

i18n is short for internationalization, and in JavaScript it usually refers to the built-in Intl APIs. These APIs help you display data in the format that a user's locale expects instead of using one fixed format for everyone.

At a high level, Intl answers questions like: What date format should I show? Which decimal separator should I use? How should I sort strings in this language?

2. Why JavaScript i18n (Intl.*) Matters

Many apps are used by people who do not share the same date, time, or number conventions. If you format everything using one culture's rules, users may misunderstand prices, deadlines, or names.

Intl matters because it lets you:

It is especially useful in dashboards, ecommerce sites, calendars, analytics tools, and any product with global users. If your app only targets one locale, you may still use it to keep formatting consistent and robust.

3. Core Strengths and Design Goals

The main goal of Intl is to separate data from presentation. You store a date or number once, then format it differently depending on the locale and options.

Unlike manual string building, Intl knows about things like numbering systems, calendars, and grammatical differences that are difficult to reproduce reliably by hand.

4. Where JavaScript i18n (Intl.*) Fits in the Ecosystem

Intl is part of the JavaScript runtime, not a separate package. In browsers, it is available in modern engines. In Node.js, it is also built in, though the available locale data can vary depending on how Node was built.

It often complements other APIs such as Date, Array.prototype.sort(), and String.prototype.localeCompare(). When you need translation of full sentences, you usually need a separate message library or localization workflow; Intl is mainly for formatting and comparison.

5. Key Features at a Glance

APIWhat it doesCommon use
Intl.DateTimeFormatFormats dates and timesCalendars, timestamps, schedules
Intl.NumberFormatFormats numbers, currency, percentPrices, metrics, percentages
Intl.CollatorCompares strings using locale rulesSorting names, search lists
Intl.RelativeTimeFormatFormats relative times"Yesterday", "in 5 minutes"
Intl.PluralRulesChooses plural categoriesPlural-sensitive labels
Intl.ListFormatFormats lists naturally"A, B, and C"

These APIs are separate because each task has its own rules. Date formatting is not the same as number formatting, and string sorting is not the same as string equality.

6. How JavaScript i18n (Intl.*) Compares to Alternatives

ApproachStrengthsWeaknesses
Intl APIsBuilt in, locale-aware, standard, widely supportedDoes not translate full UI text by itself
Manual formattingFull control for a single fixed formatHard to maintain, locale bugs, repeated code
Third-party i18n librariesGreat for message translation and advanced workflowsExtra dependency, often still uses Intl underneath

Dates and numbers vs manual strings

Manual formatting can be fine for prototypes, but it quickly becomes fragile when users expect regional formats. For example, a hard-coded date string may be readable to you but confusing to someone in another locale.

Intl vs translation libraries

Translation libraries usually handle message catalogs, plural text, interpolation, and route switching. Intl focuses on the formatting layer. In many apps, you use both: translation for words, Intl for dates and numbers.

7. Common Misconceptions

Beginners often assume internationalization is only about translating text, but formatting is just as important. The following misconceptions come up frequently:

8. Who Uses JavaScript i18n (Intl.*) and For What

If your product has users outside a single country, you will usually benefit from using Intl somewhere in the stack.

9. Typical Learning Path

A good path for learning Intl is to start with the most visible formatting tasks, then move into comparison and advanced locale behavior.

  1. Learn Intl.NumberFormat and Intl.DateTimeFormat.
  2. Practice formatting currency, percentages, and relative time.
  3. Use Intl.Collator and localeCompare() for sorting.
  4. Explore Intl.ListFormat and Intl.PluralRules.
  5. Study time zones, calendars, and server/client consistency.

Once you are comfortable with those pieces, you can design a full localization strategy instead of formatting values one by one.

10. Key Points

11. Next Steps

12. Final Summary

JavaScript's Intl APIs are the standard way to format values for different locales. They solve a real problem: the same number, date, or string may need to look different depending on the user's language and region.

For most developers, the best starting points are Intl.DateTimeFormat and Intl.NumberFormat. From there, you can add string collation, relative time, and plural handling as your app grows.

Use Intl whenever formatting needs to be correct, user-friendly, and locale-aware. If you also need translated UI copy, pair it with a dedicated localization workflow so your app handles both formatting and language well.