-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
56 lines (50 loc) · 10.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html><html class="default" lang="en" data-base="."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Unicode MessageFormat for JavaScript</title><link rel="icon" href="assets/favicon.svg" type="image/svg+xml"/><meta name="description" content="Documentation for Unicode MessageFormat for JavaScript"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"><a href="https://messageformat.github.io/mf1/">MF1 (v3) docs</a><a href="https://github.com/messageformat/messageformat">GitHub</a></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">Unicode MessageFormat for JavaScript</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>Unicode MessageFormat for JavaScript</h1></div><div class="tsd-panel tsd-typography"><p>This library provides a formatter and other tools for <a href="https://unicode.org/reports/tr35/tr35-messageFormat.html">Unicode MessageFormat 2.0</a> (MF2),
the new standard for localization developed by the <a href="https://github.com/unicode-org/message-format-wg">MessageFormat Working Group</a>.</p>
<p>This includes a formatter that can be used as a polyfill for
the proposed <a href="https://github.com/tc39/proposal-intl-messageformat/">ECMA-402 Intl.MessageFormat</a> formatter.</p>
<p>The API provided by this library is current as of the <a href="https://www.unicode.org/reports/tr35/tr35-75/tr35-messageFormat.html">LDML 47</a> (March 2025)
Final version of the MF2 specification.</p>
<pre><code class="sh"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-3">--save-exact</span><span class="hl-1"> </span><span class="hl-2">messageformat@next</span>
</code><button type="button">Copy</button></pre>
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">MessageFormat</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">'messageformat'</span><span class="hl-1">;</span><br/><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-6">msg</span><span class="hl-1"> = </span><span class="hl-2">'Today is {$today :datetime dateStyle=medium}'</span><span class="hl-1">;</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-6">mf</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">MessageFormat</span><span class="hl-1">(</span><span class="hl-2">'en'</span><span class="hl-1">, </span><span class="hl-5">msg</span><span class="hl-1">);</span><br/><br/><span class="hl-5">mf</span><span class="hl-1">.</span><span class="hl-0">format</span><span class="hl-1">({ </span><span class="hl-5">today:</span><span class="hl-1"> </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Date</span><span class="hl-1">(</span><span class="hl-2">'2022-02-02'</span><span class="hl-1">) });</span><br/><span class="hl-7">// 'Today is Feb 2, 2022'</span>
</code><button type="button">Copy</button></pre>
<p>The library also provides a number of other tools and utilities for MF2, such as:</p>
<ul>
<li>
<p>MF2 data model conversion tools</p>
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">parseMessage</span><span class="hl-1">, </span><span class="hl-5">stringifyMessage</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">'messageformat'</span><span class="hl-1">;</span>
</code><button type="button">Copy</button></pre>
</li>
<li>
<p>MF2 data model validation and transformation tools</p>
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">validate</span><span class="hl-1">, </span><span class="hl-5">visit</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">'messageformat'</span><span class="hl-1">;</span>
</code><button type="button">Copy</button></pre>
</li>
<li>
<p>Concreate Syntax Tree (CST) tools for MF2</p>
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> { </span><span class="hl-5">parseCST</span><span class="hl-1">, </span><span class="hl-5">messageFromCST</span><span class="hl-1">, </span><span class="hl-5">stringifyCST</span><span class="hl-1"> } </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">'messageformat/cst'</span><span class="hl-1">;</span>
</code><button type="button">Copy</button></pre>
</li>
<li>
<p>Utilities for building custom function handlers for MF2</p>
<pre><code class="js"><span class="hl-4">import</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">DraftFunctions</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-5">asPositiveInteger</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-5">asString</span><br/><span class="hl-1">} </span><span class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">'messageformat/functions'</span><span class="hl-1">;</span>
</code><button type="button">Copy</button></pre>
</li>
</ul>
<p>In addition to supporting MF2 syntax,
compilers and formatting function runtimes are also provided for
ICU MessageFormat and Fluent messages:</p>
<ul>
<li><a href="https://www.npmjs.com/package/@messageformat/icu-messageformat-1">@messageformat/icu-messageformat-1</a></li>
<li><a href="https://www.npmjs.com/package/@messageformat/fluent">@messageformat/fluent</a></li>
</ul>
<p>For more information on the types and functions provided by this package,
see the <a href="https://messageformat.github.io/">documentation site</a>.</p>
<div class="tsd-alert tsd-alert-important"><div class="tsd-alert-title"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><use href="assets/icons.svg#icon-alertImportant"></use></svg><span>Important</span></div><p>
The v4 release of the <code>messageformat</code> package has
an entirely different API compared to its earlier major releases,
which were built on top of ICU MessageFormat, aka "MF1".
For that,
please see <a href="https://www.npmjs.com/package/@messageformat/core"><code>@messageformat/core</code></a> instead.</p>
</div>
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav id="tsd-sidebar-links" class="tsd-navigation"><a href="https://messageformat.github.io/mf1/" class="tsd-nav-link">MF1 (v3) docs</a><a href="https://github.com/messageformat/messageformat" class="tsd-nav-link">GitHub</a></nav><nav class="tsd-navigation"><a href="modules.html">Unicode MessageFormat for JavaScript</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>