Skip to content

Commit

Permalink
Refactor locale scripts & generate types and docs (#3276)
Browse files Browse the repository at this point in the history
Closes #3232 

### Summary

- Create `locale.js` for every plugin instead of `this.defaultLocale` in the class
- Complete refactor of locale scripts
  - No dynamic plugin class imports with hacks to mimic the environment in order to get the `defaultLocale`.
  - Separate tests and build in separate files
  - Add two modes for test file, `unused` (fails hard) and `warnings`
- Generate docs
  - Use remark to cleanly mutate the file
  - Rename some doc files to match the plugin name (such as `statusbar` --> `status-bar`)
  - Comments in `locale.js` are kept and are present in the docs as well.
- Generate types
  • Loading branch information
Murderlon committed Nov 10, 2021
1 parent 3fdc55b commit 00094af
Show file tree
Hide file tree
Showing 67 changed files with 1,177 additions and 883 deletions.
295 changes: 0 additions & 295 deletions bin/locale-packs.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -135,7 +135,7 @@
"build:angular": "yarn workspace @uppy/angular build:release",
"build:js": "npm-run-all build:lib build:companion build:locale-pack build:svelte build:angular build:bundle",
"build:lib": "yarn node ./bin/build-lib.js",
"build:locale-pack": "yarn node --experimental-abortcontroller ./bin/locale-packs.js build",
"build:locale-pack": "yarn workspace locale-pack build && eslint packages/@uppy/locales/src/en_US.js --fix && yarn workspace locale-pack test unused",
"build": "npm-run-all --parallel build:js build:css --serial size",
"contributors:save": "yarn node ./bin/update-contributors.mjs",
"dev:browsersync": "yarn workspace @uppy-example/dev start",
Expand All @@ -156,7 +156,8 @@
"test:companion": "yarn workspace @uppy/companion test",
"test:endtoend:local": "yarn workspace @uppy-tests/end2end test:endtoend:local",
"test:endtoend": "yarn workspace @uppy-tests/end2end test:endtoend",
"test:locale-packs": "yarn node ./bin/locale-packs.js test",
"test:locale-packs:unused": "yarn workspace locale-pack test unused",
"test:locale-packs:warnings": "yarn workspace locale-pack test warnings",
"test:type": "yarn workspaces foreach -piv --include '@uppy/*' --exclude '@uppy/{angular,react-native,locales,companion,provider-views,robodog,svelte}' exec tsd",
"test:unit": "yarn run build:lib && jest --env jsdom",
"test:watch": "jest --env jsdom --watch",
Expand Down
8 changes: 3 additions & 5 deletions packages/@uppy/aws-s3/src/index.js
Expand Up @@ -31,6 +31,8 @@ const { RequestClient } = require('@uppy/companion-client')
const MiniXHRUpload = require('./MiniXHRUpload')
const isXml = require('./isXml')

const locale = require('./locale')

function resolveUrl (origin, link) {
return new URL(link, origin || undefined).toString()
}
Expand Down Expand Up @@ -108,11 +110,7 @@ module.exports = class AwsS3 extends BasePlugin {
this.id = this.opts.id || 'AwsS3'
this.title = 'AWS S3'

this.defaultLocale = {
strings: {
timedOut: 'Upload stalled for %{seconds} seconds, aborting.',
},
}
this.defaultLocale = locale

const defaultOptions = {
timeout: 30 * 1000,
Expand Down
5 changes: 5 additions & 0 deletions packages/@uppy/aws-s3/src/locale.js
@@ -0,0 +1,5 @@
module.exports = {
strings: {
timedOut: 'Upload stalled for %{seconds} seconds, aborting.',
},
}
9 changes: 4 additions & 5 deletions packages/@uppy/box/src/index.js
Expand Up @@ -3,6 +3,8 @@ const { Provider } = require('@uppy/companion-client')
const { ProviderViews } = require('@uppy/provider-views')
const { h } = require('preact')

const locale = require('./locale')

module.exports = class Box extends UIPlugin {
static VERSION = require('../package.json').version

Expand Down Expand Up @@ -32,11 +34,8 @@ module.exports = class Box extends UIPlugin {
pluginId: this.id,
})

this.defaultLocale = {
strings: {
pluginNameBox: 'Box',
},
}
this.defaultLocale = locale

this.i18nInit()
this.title = this.i18n('pluginNameBox')

Expand Down
5 changes: 5 additions & 0 deletions packages/@uppy/box/src/locale.js
@@ -0,0 +1,5 @@
module.exports = {
strings: {
pluginNameBox: 'Box',
},
}

0 comments on commit 00094af

Please sign in to comment.