JSPM

  • Created
  • Published
  • Downloads 1099654
  • Score
    100M100P100Q113326F
  • License BSD

Parses ICU message strings to an AST that can be used to format the messages for a person's locale.

Package Exports

  • intl-messageformat-parser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (intl-messageformat-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

intl-messageformat-parser

Parses ICU message strings to an AST that can be used to format the messages for a person's locale.

Given a message like this:

var photosMsg = 'On {takenDate, date, short} {name} took {numPhotos, plural,' +
    '0= {no photos :(}' +
    '1= {one photo.}' +
    'other {# photos!}}';

parser.parse(msg);

This parser will produce this AST:

{
    "type": "messageFormatPattern",
    "elements": [
        {
            "type": "messageTextElement",
            "value": "On "
        },
        {
            "type": "argumentElement",
            "id": "takenDate",
            "format": {
                "type": "dateFormat",
                "style": "short"
            }
        },
        {
            "type": "messageTextElement",
            "value": " "
        },
        {
            "type": "argumentElement",
            "id": "name",
            "format": null
        },
        {
            "type": "messageTextElement",
            "value": " took "
        },
        {
            "type": "argumentElement",
            "id": "numPhotos",
            "format": {
                "type": "pluralFormat",
                "offset": 0,
                "options": [
                    {
                        "type": "optionalFormatPattern",
                        "selector": "0=",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "no photos :("
                                }
                            ]
                        }
                    },
                    {
                        "type": "optionalFormatPattern",
                        "selector": "1=",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "one photo."
                                }
                            ]
                        }
                    },
                    {
                        "type": "optionalFormatPattern",
                        "selector": "other",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "# photos!"
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

License

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