![]() ![]() It’s great because once we have created a specialized format function, we can use it multiple times. Here instead of calling a format method directly, we can assign it as a function. We can use navigator.language - the preferred language for the user, which we use as a locale: Soon, we will see more comprehensive examples. It contains only language and country codes. Then we call the format() method with a provided Date object: const date = new Date("") const format = dateFormatterAT.format(date) // "" Intl.Collator - language-sensitive string comparison.Ĭreating any of these objects follows a simple pattern: const formatter = new Intl.ctor(locales, options) įor instance, the “ de-AT” locale: German language as it’s used in Austria: const dateFormatterAT = new Intl.DateTimeFormat("de-AT").Intl.PluralRules - plural sensitive formatting and plural language rules.Intl.NumberFormat - language-sensitive number formatting.Intl.DateTimeFormat - language-sensitive date and time formatting.The Intl object provides access to several constructors, like: JavaScript implements Internationalization API specification and defines the built-in Intl object.Īnd what makes it so useful is that it has great cross-browser compatibility and Node.js support: Let’s get started! Įxamples of internationalization could be Unicode support, user interface customization for different alphabets, or array sorting of non-English strings. The number 18 stands for the number of letters between the first ‘i’ and the last ‘n’. Internationalization (i18n) involves adding support for different languages and countries in your app. It’s simpler for users to deal with known notations for dates, currencies, and numbers. By Alex Permyakov How to get started with internationalization in JavaScript Photo by Vladislav Klapin on Unsplashīy adapting our apps for different languages and countries, we provide a better user experience.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |