unsplash / intlc

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

ICU formatter #129

Closed OliverJAsh closed 1 year ago

OliverJAsh commented 2 years ago

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}}
    }
}
samhh commented 2 years ago

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?

OliverJAsh commented 2 years ago

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.

samhh commented 1 year ago

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?).