Skip to content

Commit

Permalink
aws-s3: add default locale for MiniXHRUpload, fixes #2459 (#2477)
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop authored Aug 27, 2020
1 parent 9b749e6 commit bf48826
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3/src/MiniXHRUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = class MiniXHRUpload {

this.requests = opts.__queue
this.uploaderEvents = Object.create(null)
this.i18n = opts.i18n
}

_getOptions (file) {
Expand Down
24 changes: 23 additions & 1 deletion packages/@uppy/aws-s3/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// If global `URL` constructor is available, use it
const URL_ = typeof URL === 'function' ? URL : require('url-parse')
const { Plugin } = require('@uppy/core')
const Translator = require('@uppy/utils/lib/Translator')
const RateLimitedQueue = require('@uppy/utils/lib/RateLimitedQueue')
const settle = require('@uppy/utils/lib/settle')
const hasProperty = require('@uppy/utils/lib/hasProperty')
Expand Down Expand Up @@ -78,6 +79,12 @@ module.exports = class AwsS3 extends Plugin {
this.id = this.opts.id || 'AwsS3'
this.title = 'AWS S3'

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

const defaultOptions = {
timeout: 30 * 1000,
limit: 0,
Expand All @@ -87,11 +94,24 @@ module.exports = class AwsS3 extends Plugin {

this.opts = { ...defaultOptions, ...opts }

this.i18nInit()

this.client = new RequestClient(uppy, opts)
this.handleUpload = this.handleUpload.bind(this)
this.requests = new RateLimitedQueue(this.opts.limit)
}

setOptions (newOpts) {
super.setOptions(newOpts)
this.i18nInit()
}

i18nInit () {
this.translator = new Translator([this.defaultLocale, this.uppy.locale, this.opts.locale])
this.i18n = this.translator.translate.bind(this.translator)
this.setPluginState() // so that UI re-renders and we see the updated locale
}

getUploadParameters (file) {
if (!this.opts.companionUrl) {
throw new Error('Expected a `companionUrl` option containing a Companion address.')
Expand Down Expand Up @@ -262,10 +282,12 @@ module.exports = class AwsS3 extends Plugin {
getResponseError: defaultGetResponseError
}

// Only for MiniXHRUpload, remove once we can depend on XHRUpload directly again
xhrOptions.i18n = this.i18n

// Revert to `this.uppy.use(XHRUpload)` once the big comment block at the top of
// this file is solved
this._uploader = new MiniXHRUpload(this.uppy, xhrOptions)
this._uploader.i18n = this.uppy.i18n
}

uninstall () {
Expand Down

0 comments on commit bf48826

Please sign in to comment.