Intl API
Also Known As
Intl
internationalisation
i18n JavaScript
NumberFormat
DateTimeFormat
TL;DR
The built-in JavaScript internationalisation API — format numbers, dates, currencies, relative times, and lists correctly for any locale without external libraries.
Explanation
The Intl API provides: Intl.NumberFormat (numbers, currencies, percentages), Intl.DateTimeFormat (dates, times with locale-aware formatting), Intl.RelativeTimeFormat ('2 days ago', 'in 3 hours'), Intl.ListFormat ('A, B, and C'), Intl.Collator (locale-aware string sorting), Intl.PluralRules (correct pluralisation per locale), and Intl.Segmenter (word/sentence boundaries). All major browsers support it. It handles locale-specific rules like Arabic RTL, German ordinal numbers, Japanese date formats, and Indian number grouping.
Common Misconception
✗ You need a library like moment.js or date-fns for locale-aware formatting — the built-in Intl API handles most formatting needs natively with no dependencies.
Why It Matters
Hardcoded date and number formats break for international users — Intl.DateTimeFormat and Intl.NumberFormat automatically apply the user's locale conventions with no extra code.
Common Mistakes
- Creating a new Intl.NumberFormat on every call in a loop — formatters are expensive to construct; cache them.
- Not using navigator.language for the user's locale — hardcoding 'en-US' breaks for international users.
- Using Intl.RelativeTimeFormat without specifying the unit — 'days', 'hours' must be explicit.
- Forgetting Intl.Collator for sorting strings — standard < operator gives wrong order for accented characters.
Code Examples
✗ Vulnerable
// Manual formatting — locale-unaware:
const price = '$' + amount.toFixed(2); // Wrong for non-US users
const date = month + '/' + day + '/' + year; // Ambiguous internationally
// Wrong sort order for accented chars:
words.sort((a, b) => a < b ? -1 : 1); // Wrong for 'café' vs 'can'
✓ Fixed
// Intl API — automatic locale handling:
const price = new Intl.NumberFormat(navigator.language, {
style: 'currency', currency: 'USD'
}).format(amount); // '1,234.56' (US) or '1.234,56 $' (DE)
const date = new Intl.DateTimeFormat(navigator.language, {
year: 'numeric', month: 'long', day: 'numeric'
}).format(new Date()); // 'March 16, 2026' or '16. März 2026'
const relative = new Intl.RelativeTimeFormat(navigator.language)
.format(-2, 'day'); // '2 days ago' or 'il y a 2 jours'
words.sort(new Intl.Collator(navigator.language).compare); // Correct sort
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
39
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Google 9
Amazonbot 8
Perplexity 8
Unknown AI 3
Ahrefs 2
Majestic 1
Also referenced
How they use it
crawler 28
crawler_json 1
pre-tracking 2
Related categories
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: Low
⚡ Quick Fix
Use Intl.NumberFormat, Intl.DateTimeFormat, and Intl.RelativeTimeFormat for all user-facing numbers, dates, and relative times — they respect the user's locale without any library
📦 Applies To
javascript ES2015
web
cli
🔗 Prerequisites
🔍 Detection Hints
Hardcoded date format strings; new Date().toLocaleDateString() without locale; manual currency formatting with .toFixed(2)
Auto-detectable:
✗ No
eslint
typescript
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Low
✓ Auto-fixable
Fix: Low
Context: Function