unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ICU formatter

OliverJAsh opened this issue · comments

It would be super helpful to have a tool to format / pretty print ICU messages. Currently I have to do this by hand.

Before formatting:

{hasTags, boolean, true {{type, select, overLimit {{upperLimit, number}+ best free {formattedListOfTags} photos on Unsplash} belowLimit {{photoTotal, number} best free {formattedListOfTags} photos on Unsplash}}} false {{type, select, overLimit {{upperLimit, number}+ best free photos on Unsplash} belowLimit {{photoTotal, number} best free photos on Unsplash}}}}

After formatting:

{hasTags, boolean,
    true {{type, select,
        overLimit {{upperLimit, number}+ best free {formattedListOfTags} photos on Unsplash}
        belowLimit {{photoTotal, number} best free {formattedListOfTags} photos on Unsplash}}
    }
    false {{type, select,
        overLimit {{upperLimit, number}+ best free photos on Unsplash}
        belowLimit {{photoTotal, number} best free photos on Unsplash}}
    }
}

I'm wondering what this looks like in the CLI taking JSON into account. A format command would be useful, but in JSON can/should it be multiline?

Good point. In JSON I guess we would have to use newline characters instead.

FWIW so far my use case for this feature request has always been to format the message without the surrounding JSON.

With #25 in mind I'd like intlc format to be reserved. Perhaps this could have intlc prettify, or intlc explode (where we're sort of exploding interpolations vertically?).