unsplash / intlc

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

Add --indent option #195

Closed samhh closed 1 year ago

samhh commented 1 year ago

Closes #194. Once this is merged I'll release 0.8.

$ cat x.json
{
  "x": { "message": "Hello {name}" },
  "y": { "message": "Today is a {day, select, Friday {glorious} other {fine}} day." },
}
$ # Default behaviour is unchanged, we still print tabs.
$ 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
    }
}
$ # Minification is likewise unchanged, even in the presence of --indent.
$ intlc flatten --minify --indent 4 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}}
$ # The new --indent option accepts "tab", "tabs", or a natural number describing the number of spaces with which to indent. "tab" and "tabs" are equivalent to the default behaviour.
$ intlc flatten --indent tabs 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
    }
}
$ # But we can now indent with spaces!
$ intlc flatten --indent 2 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
  }
}
$ # Even if you like really extreme indentation...
$ intlc flatten --indent 12 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
            }
}