Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 62eaff0

Browse files
committed
Merge pull request #4 from yahoo/readme
Add more content to README
2 parents f04c64f + 9e6db95 commit 62eaff0

3 files changed

Lines changed: 66 additions & 17 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

2929
--------------------------------------------------------------------------------
3030

31-
Inspired by and derivied from:
31+
Inspired by and derived from:
3232
messageformat.js https://github.com/SlexAxton/messageformat.js
3333
Copyright 2014 Alex Sexton
3434
Apache License, Version 2.0

README.md

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,63 @@
1-
intl-messageformat-parser
1+
Intl MessageFormat Parser
22
=========================
33

4-
Parses ICU message strings to an AST that can be used to format the messages for
5-
a person's locale.
4+
Parses [ICU Message strings][ICU] into an AST via JavaScript.
65

7-
[![npm Version](https://img.shields.io/npm/v/intl-messageformat-parser.svg?style=flat)][npm]
8-
[![Dependency Status](https://img.shields.io/david/yahoo/intl-messageformat-parser.svg?style=flat)][david]
6+
[![npm Version][npm-badge]][npm]
7+
[![Build Status][travis-badge]][travis]
8+
[![Dependency Status][david-badge]][david]
9+
10+
11+
Overview
12+
--------
13+
14+
This package implements a parser in JavaScript that parses the industry standard [ICU Message strings][ICU] — used for internationalization — into an AST. The produced AST can then be used by a compiler, like [`intl-messageformat`][intl-mf], to produce localized formatted strings for display to users.
15+
16+
This parser is written in [PEG.js][], a parser generator for JavaScript. This parser's implementation was inspired by and derived from Alex Sexton's [messageformat.js][] project. The differences from Alex's implementation are:
17+
18+
- This project is standalone.
19+
- It's authored as ES6 modules compiled to CommonJS and the Bundle format for the browser.
20+
- The produced AST is more descriptive and uses recursive structures.
21+
- The keywords used in the AST match the ICU Message "spec".
922

10-
[npm]: https://www.npmjs.org/package/intl-messageformat-parser
11-
[david]: https://david-dm.org/yahoo/intl-messageformat-parser
1223

1324
Usage
1425
-----
1526

16-
Given a message like this:
27+
### Loading in the Browser
28+
29+
The `dist/` folder contains the version of this package for use in the browser, and it can be loaded and used like this:
30+
31+
```html
32+
<script src="intl-messageformat-parser/dist/parser.min.js"></script>
33+
<script>
34+
IntlMessageFormatParser.parse('...');
35+
</script>
36+
```
37+
38+
### Loading in Node.js
39+
40+
This package can also be `require()`-ed in Node.js:
1741

1842
```js
19-
var photosMsg = 'On {takenDate, date, short} {name} took {numPhotos, plural,' +
20-
'=0 {no photos :(}' +
21-
'=1 {one photo.}' +
22-
'other {# photos!}}';
43+
var parser = require('intl-messageformat-parser');
44+
parser.parse('...');
45+
```
46+
47+
### Example
48+
49+
Given an ICU Message string like this:
50+
51+
```
52+
On {takenDate, date, short} {name} took {numPhotos, plural,
53+
=0 {no photos.}
54+
=1 {one photo.}
55+
other {# photos.}
56+
}
57+
```
2358

59+
```js
60+
// Assume `msg` is the string above.
2461
parser.parse(msg);
2562
```
2663

@@ -70,7 +107,7 @@ This parser will produce this AST:
70107
"elements": [
71108
{
72109
"type": "messageTextElement",
73-
"value": "no photos :("
110+
"value": "no photos."
74111
}
75112
]
76113
}
@@ -96,7 +133,7 @@ This parser will produce this AST:
96133
"elements": [
97134
{
98135
"type": "messageTextElement",
99-
"value": "# photos!"
136+
"value": "# photos."
100137
}
101138
]
102139
}
@@ -108,10 +145,22 @@ This parser will produce this AST:
108145
}
109146
```
110147

148+
111149
License
112150
-------
113151

114152
This software is free to use under the Yahoo! Inc. BSD license.
115153
See the [LICENSE file][] for license text and copyright information.
116154

117-
[LICENSE file]: /blob/master/LICENSE
155+
156+
[npm]: https://www.npmjs.org/package/intl-messageformat-parser
157+
[npm-badge]: https://img.shields.io/npm/v/intl-messageformat-parser.svg?style=flat-square
158+
[david]: https://david-dm.org/yahoo/intl-messageformat-parser
159+
[david-badge]: https://img.shields.io/david/yahoo/intl-messageformat-parser.svg?style=flat-square
160+
[travis]: https://travis-ci.org/yahoo/intl-messageformat-parser
161+
[travis-badge]: https://img.shields.io/travis/yahoo/intl-messageformat-parser.svg?style=flat-square
162+
[ICU]: http://userguide.icu-project.org/formatparse/messages
163+
[intl-mf]: https://github.com/yahoo/intl-messageformat
164+
[PEG.js]: http://pegjs.majda.cz
165+
[messageformat.js]: https://github.com/SlexAxton/messageformat.js
166+
[LICENSE file]: https://github.com/yahoo/intl-messageformat-parser/blob/master/LICENSE

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "intl-messageformat-parser",
33
"version": "1.0.0-rc-2",
4-
"description": "Parses ICU message strings to an AST that can be used to format the messages for a person's locale.",
4+
"description": "Parses ICU Message strings into an AST via JavaScript.",
55
"main": "index.js",
66
"jsnext:main": "src/parser.js",
77
"scripts": {

0 commit comments

Comments
 (0)