ECMAScript Internationalization API - Intl: Difference between revisions
From WikiMLT
Line 16: | Line 16: | ||
== Simple example == | == Simple example == | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript" class="code-continue"> | ||
const formatter = new Intl.RelativeTimeFormat("bg-BG", { style: "long" }); | const formatter = new Intl.RelativeTimeFormat("bg-BG", { style: "long" }); | ||
</syntaxhighlight><syntaxhighlight lang="javascript"> | </syntaxhighlight> | ||
<syntaxhighlight lang="javascript" class="code-continue"> | |||
formatter.format(-1, "minute"); | formatter.format(-1, "minute"); | ||
</syntaxhighlight><syntaxhighlight lang="javascript"> | </syntaxhighlight> | ||
<syntaxhighlight lang="javascript" class="code-continue"> | |||
'преди 1 минута' | 'преди 1 минута' | ||
</syntaxhighlight><noinclude> | </syntaxhighlight><noinclude> |
Revision as of 20:25, 21 March 2023
The Intl
object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. The Intl
object provides access to several constructors as well as functionality common to the internationalization constructors and other language sensitive functions.
References
- MDN:
Intl
ECMAScript Internationalization API
Simple example
const formatter = new Intl.RelativeTimeFormat("bg-BG", { style: "long" });
formatter.format(-1, "minute");
'преди 1 минута'