unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 2 forks source link

Prettified JSON #190

Closed samhh closed 1 year ago

samhh commented 1 year ago

This PR adds a --minify flag anywhere we're outputting JSON, and absent that - by default - outputs prettified JSON.

The formatting logic is mostly copied from the prettify module (which prettifies ICU for intlc prettify). As there prettified output uses tabs for indentation.

Example:

$ cat x.json
{
  "x": { "message": "Hello {name}" },
  "y": { "message": "Today is a {day, select, Friday {glorious} other {fine}} day." },
}

$ intlc flatten x.json
{
    "x": {
        "message": "Hello {name}",
        "backend": "ts",
        "description": null
    },
    "y": {
        "message": "{day, select, Friday {Today is a glorious day.} other {Today is a fine day.}}",
        "backend": "ts",
        "description": null
    }
}

$ intlc flatten x.json --minify
{"x":{"message":"Hello {name}","backend":"ts","description":null},"y":{"message":"{day, select, Friday {Today is a glorious day.} other {Today is a fine day.}}","backend":"ts","description":null}}

Closes #47.