From 960f6daf6abed57099240f6471ca4cccd342a10f Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:38:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=88=AF=20fix:=20Accept=20Locale=20Count?= =?UTF-8?q?=20Placeholders=20in=20Locize=20Plural=20Forms=20(#17625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/validate-locize-download.mjs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/validate-locize-download.mjs b/scripts/validate-locize-download.mjs index 4f53719df4..10ad23bd4f 100644 --- a/scripts/validate-locize-download.mjs +++ b/scripts/validate-locize-download.mjs @@ -19,6 +19,7 @@ if (!baseDir || !currentDir) { const errors = []; const placeholderPattern = /\{\{[^{}]+\}\}|\{[^{}]+\}|%[-+0-9.#]*[a-zA-Z]/g; +const pluralSuffixPattern = /_(zero|one|two|few|many|other)$/; async function jsonFiles(directory, relative = '') { const entries = await readdir(path.join(directory, relative), { withFileTypes: true }); @@ -51,8 +52,17 @@ function flatten(value, prefix = '', output = new Map()) { return output; } -function placeholders(value) { - return (value.match(placeholderPattern) ?? []).sort().join('\u0000'); +/** + * i18next passes `count` to every plural form, so a locale may spell it out where English + * writes the number (`_one`: "1 chat") and omit it where its own grammar does not need it. + */ +function placeholders(value, key) { + const matches = value.match(placeholderPattern) ?? []; + const ignoreCount = pluralSuffixPattern.test(key); + return matches + .filter((match) => !ignoreCount || match.replace(/\s/g, '') !== '{{count}}') + .sort() + .join('\u0000'); } function boundaryWhitespace(value) { @@ -102,7 +112,7 @@ if (currentSet.has(englishRelative)) { const baseline = baselineValuesByFile.get(relative)?.get(key); const changedSinceBaseline = baseline === undefined || baseline !== value; if (changedSinceBaseline && typeof source === 'string' && typeof value === 'string') { - if (placeholders(source) !== placeholders(value)) { + if (placeholders(source, key) !== placeholders(value, key)) { errors.push(`${relative}: placeholder mismatch with English for ${key}`); } if (value !== value.trim() && boundaryWhitespace(source) !== boundaryWhitespace(value)) {