From d095ab2be7578fef10fe8cea16597b2b82759647 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:37:26 -0700 Subject: [PATCH] All: Fixes #10581: English: Use the plural form of a localization for negative and zero items (#10582) Co-authored-by: Laurent Cozic --- packages/lib/locale.test.ts | 2 ++ packages/lib/locale.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/lib/locale.test.ts b/packages/lib/locale.test.ts index 4c0fe92d4..f6f152998 100644 --- a/packages/lib/locale.test.ts +++ b/packages/lib/locale.test.ts @@ -19,6 +19,8 @@ describe('locale', () => { setLocale('en_GB'); expect(_n('Copy Shareable Link', 'Copy Shareable Links', 1)).toBe('Copy Shareable Link'); expect(_n('Copy Shareable Link', 'Copy Shareable Links', 2)).toBe('Copy Shareable Links'); + expect(_n('Copy Shareable Link', 'Copy Shareable Links', -2)).toBe('Copy Shareable Links'); + expect(_n('Copy Shareable Link', 'Copy Shareable Links', 0)).toBe('Copy Shareable Links'); }); it('should translate plurals - fr_FR', () => { diff --git a/packages/lib/locale.ts b/packages/lib/locale.ts index a37308404..11083dd9e 100644 --- a/packages/lib/locale.ts +++ b/packages/lib/locale.ts @@ -691,7 +691,7 @@ function _(s: string, ...args: any[]): string { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied function _n(singular: string, plural: string, n: number, ...args: any[]) { if (['en_GB', 'en_US'].includes(currentLocale_)) { - if (n > 1) return _(plural, ...args); + if (n !== 1) return _(plural, ...args); return _(singular, ...args); } else { const pluralFn = getPluralFunction(currentLocale_);