ECMAScript Internationalization API - Intl: Difference between revisions

From WikiMLT
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude><!--[[Category:JavaScript|?]]-->{{ContentArticleHeader/JavaScript}}</noinclude>
<noinclude><!--[[Category:JavaScript|?]]-->{{ContentArticleHeader/JavaScript}}</noinclude>
''The <code>Intl</code> object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. The <code>Intl</code> object provides access to several constructors as well as functionality common to the internationalization constructors and other language sensitive functions.''
{{media
| n = 1
| img = YouTube-loading.webp
| label = v
| special = youtube
| vid = 4oGWpTAY_hc
| sz = 1200
| pos = center
| ca = Web Dev Simplified on YouTube: [https://youtu.be/4oGWpTAY_hc Formatting Is So Easy With The Intl JavaScript API].
}}
== References ==
== References ==


* [https://codewithmosh.com/p/object-oriented-programming-in-javascript Code with Mosh: The Ultimate JavaScript Mastery Series - Part 2]
* MDN: '''[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl <code>Intl</code> ECMAScript Internationalization API]'''
* [https://www.w3schools.com/js/default.asp W3School: JavaScript Tutorial]


== Section 1 ==
== Simple example ==
...
<syntaxhighlight lang="javascript" class="code-continue">
 
const formatter = new Intl.RelativeTimeFormat("bg-BG", { style: "long" });
<noinclude>
</syntaxhighlight>
<syntaxhighlight lang="javascript" class="code-continue">
formatter.format(-1, "minute");
</syntaxhighlight>
<syntaxhighlight lang="javascript" class="code-continue">
'преди 1 минута'
</syntaxhighlight><noinclude>
<div id='devStage'>
<div id='devStage'>
{{devStage  
{{devStage  
  | Прндл  = JavaScript
  | Прндл  = JavaScript
  | Стадий = 2
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Създаден
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 21.03.2023
  | ИдтДт  = 21.03.2023
  | РзбДт  = {{Today}}
  | РзбДт = 21.03.2023
| АвтДт  = 21.03.2023
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/32444|32444]]
  | ИдтРв  = [[Special:Permalink/32444|32444]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/32449|32449]]
| АвтРв  = [[Special:Permalink/32450|32450]]
| УтвРв = {{REVISIONID}}
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 21:27, 21 March 2023

The Intl ob­ject is the name­space for the EC­MAScript In­ter­na­tion­al­iza­tion API, which pro­vides lan­guage sen­si­tive string com­par­i­son, num­ber for­mat­ting, and date and time for­mat­ting. The Intl ob­ject pro­vides ac­cess to sev­er­al con­struc­tors as well as func­tion­al­i­ty com­mon to the in­ter­na­tion­al­iza­tion con­struc­tors and oth­er lan­guage sen­si­tive func­tions.

Video 1. Web Dev Simplified on YouTube: Formatting Is So Easy With The Intl JavaScript API.
Video 1. Web Dev Sim­pli­fied on YouTube: For­mat­ting Is So Easy With The Intl JavaScript API.

Ref­er­ences

Sim­ple ex­am­ple

const formatter = new Intl.RelativeTimeFormat("bg-BG", { style: "long" });
formatter.format(-1, "minute");
'преди 1 минута'