cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Formatting issue #53

Closed gerukin closed 1 year ago

gerukin commented 1 year ago

Awesome library, thank you for the hard work! šŸ™‡ As a matter of fact, I switched to it because of some issues in the pre-rendering pipeline with svelte-i18n (in addition to the other benefits) and it was an exceptionally smooth transition.... with one exception. šŸ˜

Consider the following, which works:

{
    "duration": "{years, plural, =0 { } one {#幓} other {#幓}} {months, plural, =0 { } one {#ćƒ¶ęœˆ} other {#ćƒ¶ęœˆ}}"
}

And the following, which doesn't:

{
    "duration": "{years, plural, =0 { } one {#幓} other {#幓}}{months, plural, =0 { } one {#ćƒ¶ęœˆ} other {#ćƒ¶ęœˆ}}"
}

Number of TemplateLiteral quasis should be exactly one more than the number of expressions. Expected 3 quasis but got 1

The only difference is the space between the 2 main blocks.

Now I can add the space back in the middle, and instead remove the space in the first {}:

{
    "duration": "{years, plural, =0 {} one {#幓} other {#幓}} {months, plural, =0 { } one {#ćƒ¶ęœˆ} other {#ćƒ¶ęœˆ}}"
}

No error but the output (with 0 and 11 for the values) is:

() => `` 11ćƒ¶ęœˆ

No issue with values other than 0. Also, FYI it worked fine in svelte-i18n.

Thanks again!

cibernox commented 1 year ago

Thanks! I think the compiler didn't account for the posibility of a "translation path" being empty. I didn't cross my mind that it was a possibility. I'll improve the build time compiler to account for that.

cibernox commented 1 year ago

I think I've fixed it. Run npm update babel-plugin-precompile-intl and it should work.