intl

The JavaScript Internationalization API

what even is

INTERNATIONALIZATION

(aka i18n)

designing to enable localization

- Developing in a way that removes barriers to localization or international deployment

- Enabling code to support local, regional, language, or culturally related preferences

so...

WHat can we localize?

- Date/Time (obv!)

- Relative time (e.g. "in 1 day")

- Numbers (e.g. currency)

- Lists

- Plurals

using the intl api

const date = new Date('2011-12-31');
const number = 20000.75;

console.log(
 new Intl.DateTimeFormat('en-US').format(date),
 new Intl.NumberFormat('de-DE').format(number)
);

// output: 12/30/2011 20.000,75

console.log(
 date.toLocaleString('en-US')
 number.toLocaleString('de-DE')
);

// same result as above

Live coding BOOOOOOOOI

 

INTL

By Cameron Sampson

INTL

  • 87