From 55f5cad7f2070e2332832a37312045f5ff2780d3 Mon Sep 17 00:00:00 2001 From: LB Johnston Date: Tue, 8 Nov 2022 08:02:50 +1000 Subject: [PATCH] Ensure the ngettext (JS) util emulates the Django global if not present Follow up from #9617 --- client/src/utils/gettext.test.js | 5 +++-- client/src/utils/gettext.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/utils/gettext.test.js b/client/src/utils/gettext.test.js index f919c6f28b..14a677bd79 100644 --- a/client/src/utils/gettext.test.js +++ b/client/src/utils/gettext.test.js @@ -30,8 +30,9 @@ describe('gettext', () => { }); describe('ngettext', () => { - it('should return the first param if Django ngettext is not loaded', () => { - expect(ngettext('One bird', 'Many birds', 2)).toEqual('One bird'); + it('should emulate the Django ngettext function if it is not loaded', () => { + expect(ngettext('One bird', 'Many birds', 1)).toEqual('One bird'); + expect(ngettext('One bird', 'Many birds', 2)).toEqual('Many birds'); }); it('should call the global Django util if loaded', () => { diff --git a/client/src/utils/gettext.ts b/client/src/utils/gettext.ts index c5e5733a97..59f9635261 100644 --- a/client/src/utils/gettext.ts +++ b/client/src/utils/gettext.ts @@ -48,7 +48,7 @@ export function ngettext( return djangoNgettext(singular, plural, count); } - return singular; + return count === 1 ? singular : plural; } /**