transloadit / uppy

The next open source file uploader for web browsers :dog:
https://uppy.io
MIT License
29.18k stars 2.01k forks source link

Uppy.Core locale don't work in Yii2 integration #2542

Closed paskuale75 closed 3 years ago

paskuale75 commented 4 years ago

Here my js code:

var uppy = Uppy.Core({
    debug: true,
    locale: Uppy.locales.it_IT
});
uppy.use(Uppy.ProgressBar, { 
    target: \'.for-ProgressBar\',
    hideAfterFinish: false 
  });
  uppy.use(Uppy.Informer, {
    // Options
    target: \'.for-Informer\'
  })
  uppy.use(Uppy.DragDrop, { target: \'.drag-drop-area\' });
  uppy.use(Uppy.Tus, { endpoint: \'https://master.tus.io/files/\' });'

file "it_IT.min.js" it's loaded correctly (from /dist folder), but in dragDrop target I read the phrase "Drop file here" (english lang). If if I change the folder from which to load the language file and use the 'lib' folder instead of the 'dist' it returns this: Uncaught ReferenceError: module is not defined (at line _module.exports = itIT;) why ?

ajkachnic commented 4 years ago

I'm not fully sure, but it might be worth attempting to also pass the locale property to the options of DragDrop

Other than, do other uploading methods (ex. Dashboard) work with the locale?

paskuale75 commented 4 years ago

In dragDrop options not. The very strange thing is that if I do a test in a new application by simply loading the two scripts from the CDN (see below) the translation works!

<script src="https://transloadit.edgly.net/releases/uppy/v1.21.1/uppy.min.js"></script>
<script src="https://transloadit.edgly.net/releases/uppy/locales/v1.16.7/it_IT.min.js"></script>
goto-bus-stop commented 4 years ago

How is Uppy being loaded here? I'm not familiar with how Yii works.

I do have one uneducated guess...The locale files must either be loaded as a CommonJS module (usually with a bundler like browserify or webpack), or be loaded with a script tag, where they will attach to a global Uppy object. I think there is one case where this may go wrong: if the main Uppy bundle (uppy.min.js) detects an AMD environment, it registers itself as an AMD module, and the global Uppy variable is not available. Then the locale scripts cannot find the global Uppy variable, so they assume they must be in a CommonJS module. If Yii comes with require.js, then that might be what's going on.

paskuale75 commented 4 years ago

Yii2 uses the composer for both 'bower-assets' and 'npm-assets' and related classes called Asset that deal with css and js code compression, I don't know what the missing step is.

goto-bus-stop commented 4 years ago

Hmm OK. The file in lib/ is a CommonJS module, so you can't include it directly with a script tag. In the uppy package, dist/uppy.min.js is the same file as the one from the CDN. In the @uppy/locales package, dist/it_IT.min.js is the same file as the one from the CDN. So those are the files to use, but I assume you were actually doing so already.

The uppy.min.js file must be loaded before any locale files, or the locale will not be able to register itself. Could this be an ordering issue?

(e; going to add Yii to the issue title so I can better remember what this was about!)

paskuale75 commented 4 years ago

Ok, I'll try to put on "head" the js call, thank you very much