From 84bd81e525ec04094f66b9d44f6424da369472a7 Mon Sep 17 00:00:00 2001 From: Nybkox Date: Wed, 19 Feb 2025 12:14:23 +0100 Subject: [PATCH] feat: throw when found the same translation key with different default values --- common/translations-cli/extract.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/common/translations-cli/extract.js b/common/translations-cli/extract.js index 1fa2f67f4..5131336fd 100644 --- a/common/translations-cli/extract.js +++ b/common/translations-cli/extract.js @@ -37,13 +37,33 @@ async function extractAllTranslations(directories, extensions) { try { /** @type {Record} */ const allTranslations = {}; + /** @type {Record} */ + const translationKeyToFiles = {}; for (const dir of directories) { const files = await getFiles(dir, extensions); for (const file of files) { const fileTranslations = await extractTranslationsFromFile(file); - Object.assign(allTranslations, fileTranslations); + + for (const key in fileTranslations) { + if (!translationKeyToFiles[key]) { + translationKeyToFiles[key] = []; + } + + translationKeyToFiles[key].push(file); + + if (allTranslations[key] && allTranslations[key] !== fileTranslations[key]) { + console.error( + `Different translations for the same key [${key}] found. ${file}: ${ + fileTranslations[key] + }. Previous value: ${allTranslations[key]} was found in ${translationKeyToFiles[key].join(', ')}` + ); + throw new Error(`Duplicate translation key found: ${key}`); + } + + allTranslations[key] = fileTranslations[key]; + } } }