diff --git a/fileuploader-kiwiirc-plugin/package.json b/fileuploader-kiwiirc-plugin/package.json index a7dd0d5..0f1b099 100644 --- a/fileuploader-kiwiirc-plugin/package.json +++ b/fileuploader-kiwiirc-plugin/package.json @@ -12,6 +12,7 @@ "dependencies": { "@uppy/core": "^1.0.0", "@uppy/dashboard": "^1.0.0", + "@uppy/locales": "^1.5.0", "@uppy/tus": "^1.0.0", "@uppy/webcam": "^1.0.0", "core-js": "^3.0.1", @@ -28,6 +29,7 @@ "brotli-webpack-plugin": "^1.1.0", "clean-webpack-plugin": "^3.0.0", "compression-webpack-plugin": "^3.0.0", + "copy-webpack-plugin": "^5.1.1", "css-loader": "^3.0.0", "mini-css-extract-plugin": "^0.7.0", "prettier": "^1.17.0", diff --git a/fileuploader-kiwiirc-plugin/plugin.js b/fileuploader-kiwiirc-plugin/plugin.js index 4bd9227..376cd54 100644 --- a/fileuploader-kiwiirc-plugin/plugin.js +++ b/fileuploader-kiwiirc-plugin/plugin.js @@ -9,6 +9,7 @@ import Webcam from '@uppy/webcam' import '@uppy/core/dist/style.css' import '@uppy/dashboard/dist/style.css' import '@uppy/webcam/dist/style.css' +import Translator from '@uppy/utils/lib/Translator' import sidebarFileList from './components/SidebarFileList.vue' import isPromise from 'p-is-promise' import TokenManager from './token-manager'; @@ -16,6 +17,14 @@ import TokenManager from './token-manager'; const KiB = 2 ** 10 const MiB = 2 ** 20 +let scriptPath; + +(function() { + const scriptElements = document.getElementsByTagName('script'); + const thisScriptSrc = scriptElements[scriptElements.length - 1].src; + scriptPath = thisScriptSrc.substr(0, thisScriptSrc.lastIndexOf( '/' ) + 1); +})(); + function getValidUploadTarget() { const buffer = kiwi.state.getActiveBuffer() const isValidTarget = buffer && (buffer.isChannel() || buffer.isQuery()) @@ -132,6 +141,65 @@ kiwi.plugin('fileuploader', function (kiwi, log) { const dashboard = uppy.getPlugin('Dashboard') + function loadLocale(_lang) { + let lang = (_lang ? _lang : kiwi.i18n.language).split('-'); + if (lang.length !== 2) { + setDefaultLocale(); + return; + } + let langUppy = lang[0] + '_' + lang[1].toUpperCase(); + + let xhttp = new XMLHttpRequest(); + xhttp.onload = (event) => { + if (xhttp.status !== 200) { + // Failed to load the locale + setDefaultLocale(); + return; + } + setLocale(eval(xhttp.responseText)); + }; + xhttp.open('GET', scriptPath + 'plugin-fileuploader/locales/uppy/' + langUppy + '.js'); + xhttp.send(); + } + + function setDefaultLocale() { + import( + /* webpackMode: "eager" */ + `@uppy/locales/lib/en_US.js` + ).then(locale => { + setLocale(locale) + }); + } + + function setLocale(locale) { + // update uppy core + uppy.opts.locale = locale + uppy.translator = new Translator([ uppy.defaultLocale, uppy.opts.locale ]) + uppy.locale = uppy.translator.locale + uppy.i18n = uppy.translator.translate.bind(uppy.translator) + uppy.i18nArray = uppy.translator.translateArray.bind(uppy.translator) + uppy.setState() + + // update uppy plugins + uppy.iteratePlugins(function(plugin) { + if (plugin.translator) { + plugin.translator = uppy.translator + } + if (plugin.i18n) { + plugin.i18n = uppy.i18n + } + if (plugin.i18nArray) { + plugin.i18nArray = uppy.i18nArray + } + plugin.setPluginState() + }); + } + + loadLocale() + kiwi.state.$watch('user_settings.language', (lang) => { + loadLocale(lang) + }); + // expose plugin api kiwi.fileuploader.uppy = uppy kiwi.fileuploader.dashboard = dashboard diff --git a/fileuploader-kiwiirc-plugin/webpack.config.js b/fileuploader-kiwiirc-plugin/webpack.config.js index 90b3c31..6c025e7 100644 --- a/fileuploader-kiwiirc-plugin/webpack.config.js +++ b/fileuploader-kiwiirc-plugin/webpack.config.js @@ -1,5 +1,6 @@ const path = require('path'); const VueLoaderPlugin = require('vue-loader/lib/plugin'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); const CompressionPlugin = require('compression-webpack-plugin'); const BrotliPlugin = require('brotli-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); @@ -53,6 +54,13 @@ module.exports = { minRatio: 0.8, deleteOriginalAssets: false, }), + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, './node_modules/@uppy/locales/lib'), + to: 'plugin-fileuploader/locales/uppy/', + ignore: ['*.map'] + } + ]) ], devtool: 'source-map', devServer: { @@ -61,6 +69,10 @@ module.exports = { compress: true, host: process.env.HOST || 'localhost', port: process.env.PORT || 41040, + headers: { + // required for loading locales with XMLHttpRequest + "Access-Control-Allow-Origin": "*", + }, }, optimization: { minimize: true, diff --git a/fileuploader-kiwiirc-plugin/yarn.lock b/fileuploader-kiwiirc-plugin/yarn.lock index 01d7c85..5759941 100644 --- a/fileuploader-kiwiirc-plugin/yarn.lock +++ b/fileuploader-kiwiirc-plugin/yarn.lock @@ -745,6 +745,11 @@ "@uppy/utils" "1.1.0" preact "8.2.9" +"@uppy/locales@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@uppy/locales/-/locales-1.5.0.tgz#f190d074d2eee396c2c8687340ded647faf94287" + integrity sha512-PWKYS9tqkL7N/3Qj8Q/get5g2mkbnHrTnjZXLDBkJaJ2EVPgDSHLIDxLtXUaTbohF6L1qLiARtidH9cae7A29g== + "@uppy/provider-views@1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@uppy/provider-views/-/provider-views-1.1.0.tgz#f03c1af0b488b759d7ba2f11b51ecadfffe4e8f3" @@ -1472,6 +1477,27 @@ cacache@^11.3.2: unique-filename "^1.1.1" y18n "^4.0.0" +cacache@^12.0.3: + version "12.0.4" + resolved "https://registry.yarnpkg.com/cacache/-/cacache-12.0.4.tgz#668bcbd105aeb5f1d92fe25570ec9525c8faa40c" + integrity sha512-a0tMB40oefvuInr4Cwb3GerbL9xTj1D5yg0T5xrjGCGyfvbxseIXX7BAO/u/hIXdafzOI5JC3wDwHyf24buOAQ== + dependencies: + bluebird "^3.5.5" + chownr "^1.1.1" + figgy-pudding "^3.5.1" + glob "^7.1.4" + graceful-fs "^4.1.15" + infer-owner "^1.0.3" + lru-cache "^5.1.1" + mississippi "^3.0.0" + mkdirp "^0.5.1" + move-concurrently "^1.0.1" + promise-inflight "^1.0.1" + rimraf "^2.6.3" + ssri "^6.0.1" + unique-filename "^1.1.1" + y18n "^4.0.0" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -1753,6 +1779,24 @@ copy-descriptor@^0.1.0: resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= +copy-webpack-plugin@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-5.1.1.tgz#5481a03dea1123d88a988c6ff8b78247214f0b88" + integrity sha512-P15M5ZC8dyCjQHWwd4Ia/dm0SgVvZJMYeykVIVYXbGyqO4dWB5oyPHp9i7wjwo5LhtlhKbiBCdS2NvM07Wlybg== + dependencies: + cacache "^12.0.3" + find-cache-dir "^2.1.0" + glob-parent "^3.1.0" + globby "^7.1.1" + is-glob "^4.0.1" + loader-utils "^1.2.3" + minimatch "^3.0.4" + normalize-path "^3.0.0" + p-limit "^2.2.1" + schema-utils "^1.0.0" + serialize-javascript "^2.1.2" + webpack-log "^2.0.0" + core-js-compat@^3.1.1: version "3.1.4" resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.1.4.tgz#e4d0c40fbd01e65b1d457980fe4112d4358a7408" @@ -2034,6 +2078,13 @@ diffie-hellman@^5.0.0: miller-rabin "^4.0.0" randombytes "^2.0.0" +dir-glob@^2.0.0: + version "2.2.2" + resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.2.2.tgz#fa09f0694153c8918b18ba0deafae94769fc50c4" + integrity sha512-f9LBi5QWzIW3I6e//uxZoLBlUt9kcp66qo0sSCxL6YZKc75R1c4MFCoe/LaZiBGmgujvQdxc5Bn3QhfyvK5Hsw== + dependencies: + path-type "^3.0.0" + dns-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" @@ -2355,7 +2406,7 @@ finalhandler@~1.1.2: statuses "~1.5.0" unpipe "~1.0.0" -find-cache-dir@^2.0.0: +find-cache-dir@^2.0.0, find-cache-dir@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7" integrity sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ== @@ -2544,6 +2595,18 @@ glob@^7.0.3, glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.2: + version "7.1.6" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" + integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + global-modules@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780" @@ -2596,6 +2659,18 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" +globby@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680" + integrity sha1-+yzP+UAfhgCUXfral0QMypcrhoA= + dependencies: + array-union "^1.0.1" + dir-glob "^2.0.0" + glob "^7.1.2" + ignore "^3.3.5" + pify "^3.0.0" + slash "^1.0.0" + graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2: version "4.2.0" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b" @@ -2806,6 +2881,11 @@ ignore-walk@^3.0.1: dependencies: minimatch "^3.0.4" +ignore@^3.3.5: + version "3.3.10" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043" + integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug== + iltorb@^2.0.1: version "2.4.3" resolved "https://registry.yarnpkg.com/iltorb/-/iltorb-2.4.3.tgz#b489689d24c8a25a2cf170c515f97954edd45577" @@ -2835,6 +2915,11 @@ indexes-of@^1.0.1: resolved "https://registry.yarnpkg.com/indexes-of/-/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607" integrity sha1-8w9xbI4r00bHtn0985FVZqfAVgc= +infer-owner@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/infer-owner/-/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467" + integrity sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A== + inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -2997,7 +3082,7 @@ is-glob@^3.1.0: dependencies: is-extglob "^2.1.0" -is-glob@^4.0.0: +is-glob@^4.0.0, is-glob@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== @@ -3846,6 +3931,13 @@ p-limit@^2.0.0, p-limit@^2.2.0: dependencies: p-try "^2.0.0" +p-limit@^2.2.1: + version "2.3.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" + integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== + dependencies: + p-try "^2.0.0" + p-locate@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" @@ -3963,6 +4055,13 @@ path-to-regexp@0.1.7: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= +path-type@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f" + integrity sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg== + dependencies: + pify "^3.0.0" + pbkdf2@^3.0.3: version "3.0.17" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6" @@ -3979,6 +4078,11 @@ pify@^2.0.0: resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" integrity sha1-7RQaasBDqEnqWISY59yosVMw6Qw= +pify@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" + integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY= + pify@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231" @@ -4607,6 +4711,11 @@ serialize-javascript@^1.4.0, serialize-javascript@^1.7.0: resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.7.0.tgz#d6e0dfb2a3832a8c94468e6eb1db97e55a192a65" integrity sha512-ke8UG8ulpFOxO8f8gRYabHQe/ZntKlcig2Mp+8+URDP1D8vJZ0KUt7LYo07q25Z/+JVSgpr/cui9PIp5H6/+nA== +serialize-javascript@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61" + integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ== + serve-index@^1.9.1: version "1.9.1" resolved "https://registry.yarnpkg.com/serve-index/-/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239" @@ -4699,6 +4808,11 @@ simple-get@^2.7.0: once "^1.3.1" simple-concat "^1.0.0" +slash@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" + integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU= + snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"