diff --git a/packages/core/src/interpolate.test.ts b/packages/core/src/interpolate.test.ts index 0c5382085..79622391f 100644 --- a/packages/core/src/interpolate.test.ts +++ b/packages/core/src/interpolate.test.ts @@ -72,6 +72,12 @@ describe("interpolate", () => { expect(offset({ value: 3 })).toEqual("2 Books") }) + it("should compile plurals with falsy value choice", () => { + const plural = prepare("{value, plural, one {} other {# Books}}") + expect(plural({ value: 1 })).toEqual("") + expect(plural({ value: 2 })).toEqual("2 Books") + }) + it("when a value is defined (even when empty) plural will return it. Conversely, if a value is not defined, plural defaults to 'other'", () => { const plural = prepare("{value, plural, =0 {} other {#% discount}}") expect(plural({ value: 0 })).toEqual("") @@ -119,6 +125,15 @@ describe("interpolate", () => { expect(cache({ value: "n/a" })).toEqual("They") }) + it("should support select with empty string choice", () => { + const cache = prepare("{value, select, female {} other {They}}") + expect(cache({ value: "female" })).toEqual("") + expect(cache({ value: "n/a" })).toEqual("They") + const cache2 = prepare("{value, select, female {0} other {They}}") + expect(cache2({ value: "female" })).toEqual("0") + expect(cache2({ value: "n/a" })).toEqual("They") + }) + describe("Custom format", () => { const testVector = [ ["en", null, "0.1", "10%", "20%", "3/4/2017", "€0.10", "€1.00"], diff --git a/packages/core/src/interpolate.ts b/packages/core/src/interpolate.ts index f42feed61..c1f099ef1 100644 --- a/packages/core/src/interpolate.ts +++ b/packages/core/src/interpolate.ts @@ -34,7 +34,7 @@ const getDefaultFormats = ( return replaceOctothorpe(value - offset, message) }, - select: (value: string, rules) => rules[value] || rules.other, + select: (value: string, rules) => rules[value] ?? rules.other, number: ( value: number,