diff --git a/packages/@uppy/box/src/Box.jsx b/packages/@uppy/box/src/Box.jsx index 93a202a1db..087ba8ade9 100644 --- a/packages/@uppy/box/src/Box.jsx +++ b/packages/@uppy/box/src/Box.jsx @@ -32,7 +32,7 @@ export default class Box extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameBox') diff --git a/packages/@uppy/companion-client/src/Provider.js b/packages/@uppy/companion-client/src/Provider.js index 3fa017ff57..2d109b5ea7 100644 --- a/packages/@uppy/companion-client/src/Provider.js +++ b/packages/@uppy/companion-client/src/Provider.js @@ -2,6 +2,7 @@ import RequestClient from './RequestClient.js' import * as tokenStorage from './tokenStorage.js' +import locale from './locale.js' const getName = (id) => { return id.split('-').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') @@ -39,6 +40,8 @@ export default class Provider extends RequestClient { this.tokenKey = `companion-${this.pluginId}-auth-token` this.companionKeysParams = this.opts.companionKeysParams this.preAuthToken = null + + this.defaultLocale = locale } async headers () { @@ -124,9 +127,9 @@ export default class Provider extends RequestClient { const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data if (data.error) { - const { uppy } = this - const message = uppy.i18n('authAborted') - uppy.info({ message }, 'warning', 5000) + const { i18n } = this.uppy.getPlugin(this.pluginId) + const message = i18n('authAborted') + this.uppy.info({ message }, 'warning', 5000) reject(new Error('auth aborted')) } diff --git a/packages/@uppy/companion-client/src/locale.js b/packages/@uppy/companion-client/src/locale.js new file mode 100644 index 0000000000..23392e5469 --- /dev/null +++ b/packages/@uppy/companion-client/src/locale.js @@ -0,0 +1,5 @@ +export default { + strings: { + authAborted: 'Authentication aborted', + }, +} diff --git a/packages/@uppy/core/src/BasePlugin.js b/packages/@uppy/core/src/BasePlugin.js index c802f97b74..e03b1450f4 100644 --- a/packages/@uppy/core/src/BasePlugin.js +++ b/packages/@uppy/core/src/BasePlugin.js @@ -41,7 +41,11 @@ export default class BasePlugin { } i18nInit () { - const translator = new Translator([this.defaultLocale, this.uppy.locale, this.opts.locale]) + const translator = new Translator([ + ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), + this.uppy.locale, + this.opts.locale, + ]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.setPluginState() // so that UI re-renders and we see the updated locale diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index c597c97efb..fdc26ceaf1 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -198,7 +198,10 @@ class Uppy { } i18nInit () { - const translator = new Translator([this.defaultLocale, this.opts.locale]) + const translator = new Translator([ + ...(Array.isArray(this.defaultLocale) ? this.defaultLocale : [this.defaultLocale]), + this.opts.locale, + ]) this.i18n = translator.translate.bind(translator) this.i18nArray = translator.translateArray.bind(translator) this.locale = translator.locale diff --git a/packages/@uppy/core/src/locale.js b/packages/@uppy/core/src/locale.js index 16a18cf3a4..9a43be62fa 100644 --- a/packages/@uppy/core/src/locale.js +++ b/packages/@uppy/core/src/locale.js @@ -22,7 +22,6 @@ export default { noDuplicates: "Cannot add the duplicate file '%{fileName}', it already exists", companionError: 'Connection with Companion failed', - authAborted: 'Authentication aborted', companionUnauthorizeHint: 'To unauthorize to your %{provider} account, please go to %{url}', failedToUpload: 'Failed to upload %{file}', diff --git a/packages/@uppy/dropbox/src/Dropbox.jsx b/packages/@uppy/dropbox/src/Dropbox.jsx index c591933087..fad309939f 100644 --- a/packages/@uppy/dropbox/src/Dropbox.jsx +++ b/packages/@uppy/dropbox/src/Dropbox.jsx @@ -29,7 +29,7 @@ export default class Dropbox extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameDropbox') diff --git a/packages/@uppy/facebook/src/Facebook.jsx b/packages/@uppy/facebook/src/Facebook.jsx index f8ceac492e..e0eeaf0f23 100644 --- a/packages/@uppy/facebook/src/Facebook.jsx +++ b/packages/@uppy/facebook/src/Facebook.jsx @@ -32,7 +32,7 @@ export default class Facebook extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameFacebook') diff --git a/packages/@uppy/google-drive/src/GoogleDrive.jsx b/packages/@uppy/google-drive/src/GoogleDrive.jsx index 96433c33ef..381dca7c28 100644 --- a/packages/@uppy/google-drive/src/GoogleDrive.jsx +++ b/packages/@uppy/google-drive/src/GoogleDrive.jsx @@ -43,7 +43,7 @@ export default class GoogleDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameGoogleDrive') diff --git a/packages/@uppy/instagram/src/Instagram.jsx b/packages/@uppy/instagram/src/Instagram.jsx index 7ba14fd33e..850b987ba4 100644 --- a/packages/@uppy/instagram/src/Instagram.jsx +++ b/packages/@uppy/instagram/src/Instagram.jsx @@ -28,11 +28,6 @@ export default class Instagram extends UIPlugin { ) - this.defaultLocale = locale - - this.i18nInit() - this.title = this.i18n('pluginNameInstagram') - this.provider = new Provider(uppy, { companionUrl: this.opts.companionUrl, companionHeaders: this.opts.companionHeaders, @@ -42,6 +37,11 @@ export default class Instagram extends UIPlugin { pluginId: this.id, }) + this.defaultLocale = [this.provider.defaultLocale, locale] + + this.i18nInit() + this.title = this.i18n('pluginNameInstagram') + this.onFirstRender = this.onFirstRender.bind(this) this.render = this.render.bind(this) } diff --git a/packages/@uppy/onedrive/src/OneDrive.jsx b/packages/@uppy/onedrive/src/OneDrive.jsx index 6f4b939f56..d8548aceb2 100644 --- a/packages/@uppy/onedrive/src/OneDrive.jsx +++ b/packages/@uppy/onedrive/src/OneDrive.jsx @@ -34,7 +34,7 @@ export default class OneDrive extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameOneDrive') diff --git a/packages/@uppy/zoom/src/Zoom.jsx b/packages/@uppy/zoom/src/Zoom.jsx index c7c3d392ba..2b0af4bb70 100644 --- a/packages/@uppy/zoom/src/Zoom.jsx +++ b/packages/@uppy/zoom/src/Zoom.jsx @@ -30,7 +30,7 @@ export default class Zoom extends UIPlugin { pluginId: this.id, }) - this.defaultLocale = locale + this.defaultLocale = [this.provider.defaultLocale, locale] this.i18nInit() this.title = this.i18n('pluginNameZoom')