Skip to content

Commit 5899cbe

Browse files
authored
[๐Ÿ”ฅAUDIT๐Ÿ”ฅ] Fix ngettext not returning plural translations. (#2371)
๐Ÿ– _This is an audit!_ ๐Ÿ– ## Summary: This bug is in prod right now, unfortunately. Some strings are appearing untranslated. Issue: FEI-6007 ## Test plan: This was actually wrong in the tests!! So I fixed the test in the process. Author: jeresig Auditors: #frontend-infra-web, #wonder-blocks Required Reviewers: Approved By: Checks: โœ… Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), โœ… Test / Test (ubuntu-latest, 20.x, 2/2), โœ… Test / Test (ubuntu-latest, 20.x, 1/2), โœ… Lint / Lint (ubuntu-latest, 20.x), โœ… Check build sizes (ubuntu-latest, 20.x), โœ… Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), โœ… Publish npm snapshot (ubuntu-latest, 20.x), โญ๏ธ Chromatic - Skip on Release PR (changesets), โœ… Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), โญ๏ธ dependabot, โœ… Check for .changeset entries for all changed files (ubuntu-latest, 20.x), โœ… gerald Pull Request URL: #2371
1 parent b5cad0b commit 5899cbe

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-i18n": patch
3+
---
4+
5+
Fix ngettext not returning plural translations.

โ€Žpackages/wonder-blocks-i18n/src/functions/__tests__/i18n.test.tsโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("i18n", () => {
139139
const result = ngettext("Singular", "Plural", 0);
140140

141141
// Assert
142-
expect(result).toMatchInlineSnapshot(`"Plural"`);
142+
expect(result).toMatchInlineSnapshot(`"arrrr mateys"`);
143143
});
144144

145145
it("doNotTranslate should not translate", () => {

โ€Žpackages/wonder-blocks-i18n/src/functions/i18n.tsโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const ngettext: ngettextOverloads = (
210210
typeof singular === "object"
211211
? singular
212212
: {
213-
lang: "en",
213+
lang: getLocale(),
214214
// We know plural is a string if singular is not a config object
215215
messages: [singular, plural as any],
216216
};

0 commit comments

Comments
ย (0)