diff --git a/scripts/i18n-check.mjs b/scripts/i18n-check.mjs index ba63a133..c357b434 100644 --- a/scripts/i18n-check.mjs +++ b/scripts/i18n-check.mjs @@ -162,6 +162,7 @@ const source = files.filter( const CALL = /(?:\.\s*(?:t|has)|\bmsg)\(\s*'([\w.-]+)'/g const CARRIED = /\b(?:title|blurb|label|description|message|publicMessage)Key:\s*'([\w.-]+)'/g const KEY_SHAPE = /^[a-z][\w-]*(?:\.[\w-]+)+$/ +const KEY_LIST = /\w+\(\s*t\s*,\s*\[([\s\S]*?)\]\s*\)/g for (const { abs, rel } of source) { const text = await readFile(abs, 'utf8') @@ -183,6 +184,22 @@ for (const { abs, rel } of source) { ) } } + + for (const listMatch of text.matchAll(KEY_LIST)) { + for (const litMatch of listMatch[1].matchAll(new RegExp(STRING, 'g'))) { + const key = litMatch[0].slice(1, -1) + if (!KEY_SHAPE.test(key)) continue + + used.add(key) + if (allMessages[key] === undefined) { + fail( + `${rel} reads the message "${key}" through a key list passed to a translator ` + + 'helper, and no English catalog carries it. A missing message renders as its ' + + 'own key, in every language including English.', + ) + } + } + } } const orphans = messageKeys.filter((key) => !used.has(key))