Browse Source

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

Antoine du Hamel 3 years ago
parent
commit
d94c7d1232
2 changed files with 12 additions and 0 deletions
  1. 2 0
      bin/locale-packs.js
  2. 10 0
      packages/@uppy/dashboard/src/components/AddFiles.js

+ 2 - 0
bin/locale-packs.js

@@ -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}'`)
     }
   }
 }

+ 10 - 0
packages/@uppy/dashboard/src/components/AddFiles.js

@@ -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