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]; + } } }