build: harden locale pack check for unused or duplicate key (#3081)

This commit is contained in:
Antoine du Hamel 2021-08-09 19:32:44 +02:00 committed by GitHub
parent 10f595e3a8
commit d94c7d1232
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -128,6 +128,7 @@ function addLocaleToPack (localePack, plugin, pluginName) {
console.error(` Value in plugin: ${chalk.cyan(valueInPlugin)}`)
console.error(` Value in pack : ${chalk.yellow(valueInPack)}`)
console.error()
throw new Error(`Duplicate locale key: '${key}'`)
}
localePack[key] = localeStrings[key] // eslint-disable-line no-param-reassign
}
@ -139,6 +140,7 @@ function checkForUnused (fileContents, pluginName, localePack) {
const regPat = new RegExp(`(i18n|i18nArray)\\([^\\)]*['\`"]${key}['\`"]`, 'g')
if (!buff.match(regPat)) {
console.error(`⚠ defaultLocale key: ${chalk.magenta(key)} not used in plugin: ${chalk.cyan(pluginName)}`)
throw new Error(`Unused locale key: '${key}'`)
}
}
}

View file

@ -174,6 +174,16 @@ class AddFiles extends Component {
)
}
[Symbol.for('uppy test: disable unused locale key warning')] () {
// Those are actually used in `renderDropPasteBrowseTagline` method.
this.props.i18nArray('dropPasteBoth')
this.props.i18nArray('dropPasteFiles')
this.props.i18nArray('dropPasteFolders')
this.props.i18nArray('dropPasteImportBoth')
this.props.i18nArray('dropPasteImportFiles')
this.props.i18nArray('dropPasteImportFolders')
}
renderAcquirer = (acquirer) => {
return (
<div