Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization for Uppy #2766

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion apps/dashboard/app/javascript/packs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ function csrfToken() {
return csrf_token;
}

function uppyLocale() {
const cfgData = configData();
return JSON.parse(cfgData['uppyLocale']);
}

export {
maxFileSize,
transfersPath,
jobsInfoPath,
csrfToken
csrfToken,
uppyLocale
};
3 changes: 2 additions & 1 deletion apps/dashboard/app/javascript/packs/files/uppy_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Dashboard from '@uppy/dashboard'
import XHRUpload from '@uppy/xhr-upload'
import _ from 'lodash';
import {CONTENTID, EVENTNAME as DATATABLE_EVENTNAME} from './data_table.js';
import { maxFileSize, csrfToken } from '../config.js';
import { maxFileSize, csrfToken, uppyLocale } from '../config.js';

let uppy = null;

Expand Down Expand Up @@ -70,6 +70,7 @@ jQuery(function() {
maxFileSize: maxFileSize(),
},
onBeforeUpload: updateEndpoint,
locale: uppyLocale(),
});

uppy.use(EmptyDirCreator);
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
data-max-file-size="<%= Configuration.file_upload_max %>"
data-transfers-path="<%= transfers_path(format: "json") if respond_to?(:transfers_path) %>"
data-jobs-info-path="<%= jobs_info_path('delme', 'delme').gsub(/[\/]*delme[\/]*/,'') %>"
data-uppy-locale="<%= I18n.t('dashboard.uppy', :default => {}).to_json %>"
/>
</head>
<body>
Expand Down
33 changes: 33 additions & 0 deletions apps/dashboard/test/system/files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,37 @@ class FilesTest < ApplicationSystemTestCase
assert_equal 'foobar', File.read(file)
end
end

test 'uppy localization' do
with_modified_env(FILE_UPLOAD_MAX: '10') do
Dir.mktmpdir do |dir|
# No localization (default)
visit files_url(dir)
find('#upload-btn').click
find('.uppy-Dashboard-AddFiles', wait: MAX_WAIT)

src_file = 'test/fixtures/files/upload/osc-logo.png'
attach_file 'files[]', src_file, visible: false, match: :first

find('.uppy.uppy-Informer', text: /osc-logo.png exceeds [\w ]+ size of 10 B/, wait: MAX_WAIT)

# Temporarily add localization for max upload size error
en = { :dashboard => { :uppy => { :strings => { :exceedsSize => 'custom error, %{file}, %{size}' } } } }
I18n.backend.store_translations(:en, en)

visit files_url(dir)
find('#upload-btn').click
find('.uppy-Dashboard-AddFiles', wait: MAX_WAIT)

src_file = 'test/fixtures/files/upload/osc-logo.png'
attach_file 'files[]', src_file, visible: false, match: :first

find('.uppy.uppy-Informer', text: 'custom error, osc-logo.png, 10 B', wait: MAX_WAIT)

I18n.backend.reload!
# Clear browser logs
page.driver.browser.logs.get(:browser)
end
end
end
end