unsplash / intlc

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

Fix booleans not being flattened #107

Closed samhh closed 2 years ago

samhh commented 2 years ago

Fixes #104.

Another reason I don't love how flattening is implemented is that this was missed without warning.

Test case:

before {myBoolean, boolean, true {true} false {false}} {myVar, select, a {a} b {b}} after

Before:

{myVar, select, a {before {myBoolean, boolean, true {true} false {false}} a after} b {before {myBoolean, boolean, true {true} false {false}} b after}}

After:

{myBoolean, boolean, true {{myVar, select, a {before true a after} b {before true b after}}} false {{myVar, select, a {before false a after} b {before false b after}}}}
OliverJAsh commented 2 years ago

Just to check, what happens when we have multiple nested select/booleans? (Not sure if this is a valid example, I'm getting lost in the braces—we need an ICU formatter!)

{myVar, select,
  a {before {myBoolean, boolean,
    true {{myVar2, select,
        a {a2}
        b {b2}
        }
    }
    false {false}} a after
  }
  b {before {myBoolean, boolean, true {true} false {false}} b after}
}
samhh commented 2 years ago

With the number in the identifier removed:

{myVar, select, a {{myBoolean, boolean, true {{myVar, select, a {before a2 a after} b {before b2 a after}}} false {before false a after}}} b {{myBoolean, boolean, true {before true b after} false {before false b after}}}}