stefalda/react-localization

formatString not working with falsy values as parameter

Closed this issue · 2 comments

S.formatString("Value should be between {0} and {1}", 0, 10).

var valueForPlaceholder = valuesForPlaceholders[matchedKey];

here valueForPlaceholder is resolved just fine.

if (!valueForPlaceholder) {
   valueForPlaceholder = valuesForPlaceholders[0][matchedKey];
}

here (because of 'if (!0)' is true) it goes undefined.

if (isReactComponent(valueForPlaceholder)) {

here it crashes

I got the same error.

I resolved it with adding .toString.

strings.formatString(strings.myString, 0.toString())

This was my fault, I have another PR incoming shortly... You'd think this is my first time writing JS 😩