Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fileuploader-kiwiirc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions fileuploader-kiwiirc-plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -66,7 +67,21 @@ kiwi.plugin('fileuploader', function (kiwi, log) {

const tokenManager = new TokenManager()

function loadLocale(_lang) {
try {
let lang = (_lang ? _lang : kiwi.i18n.language).split('-')
lang = lang[0] + '_' + lang[1].toUpperCase()
return require(/* webpackMode: "eager" */ '@uppy/locales/lib/' + lang)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done with static import paths? Import paths that are determined at runtime can cause problems like webpack including unnecessary files in the bundle because it can't tell what's going to be needed, etc.

} catch (e) {
return require(/* webpackMode: "eager" */ '@uppy/locales/lib/en_US')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also use the import() syntax, since we're already using import statements instead of require everywhere else.

}
}

// load our currnet locale or fallback
let locale = loadLocale()

const uppy = Uppy({
locale: locale,
autoProceed: false,
onBeforeFileAdded: (currentFile, files) => {
// throws if invalid, canceling the file add
Expand Down Expand Up @@ -132,6 +147,30 @@ kiwi.plugin('fileuploader', function (kiwi, log) {

const dashboard = uppy.getPlugin('Dashboard')

kiwi.state.$watch('user_settings.language', (lang) => {
// update uppy core
uppy.opts.locale = loadLocale(lang)
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()
});
});

// expose plugin api
kiwi.fileuploader.uppy = uppy
kiwi.fileuploader.dashboard = dashboard
Expand Down
5 changes: 5 additions & 0 deletions fileuploader-kiwiirc-plugin/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down