From 01b34ec1fbbe15b9c42ea3f7b71beab90e906cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 23 Jul 2015 17:17:48 +0200 Subject: [PATCH] add getLangText for reactfineuploader --- .../file_drag_and_drop_dialog.js | 12 ++++++++---- .../file_drag_and_drop_preview.js | 2 +- .../file_drag_and_drop_preview_other.js | 2 +- .../ascribe_uploader/react_s3_fine_uploader.js | 16 +++++++++------- js/utils/file_utils.js | 3 +++ 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/js/components/ascribe_uploader/file_drag_and_drop_dialog.js b/js/components/ascribe_uploader/file_drag_and_drop_dialog.js index d8b3dc1e..c3633af8 100644 --- a/js/components/ascribe_uploader/file_drag_and_drop_dialog.js +++ b/js/components/ascribe_uploader/file_drag_and_drop_dialog.js @@ -2,6 +2,8 @@ import React from 'react'; +import { getLangText } from '../../utils/lang_utils'; + let FileDragAndDropDialog = React.createClass({ propTypes: { hasFiles: React.PropTypes.bool, @@ -15,17 +17,19 @@ let FileDragAndDropDialog = React.createClass({ } else { if(this.props.multipleFiles) { return ( - Click or drag to add files + + {getLangText('Click or drag to add files')} + ); } else { return ( -

Drag a file here

-

or

+

{getLangText('Drag a file here')}

+

{getLangText('or')}

- choose a file to upload + {getLangText('choose a file to upload')}
); diff --git a/js/components/ascribe_uploader/file_drag_and_drop_preview.js b/js/components/ascribe_uploader/file_drag_and_drop_preview.js index b4dd84be..9c6cdbdd 100644 --- a/js/components/ascribe_uploader/file_drag_and_drop_preview.js +++ b/js/components/ascribe_uploader/file_drag_and_drop_preview.js @@ -4,7 +4,7 @@ import React from 'react'; import FileDragAndDropPreviewImage from './file_drag_and_drop_preview_image'; import FileDragAndDropPreviewOther from './file_drag_and_drop_preview_other'; -import { getLangText } from '../../utils/lang_utils.js' +import { getLangText } from '../../utils/lang_utils.js'; let FileDragAndDropPreview = React.createClass({ diff --git a/js/components/ascribe_uploader/file_drag_and_drop_preview_other.js b/js/components/ascribe_uploader/file_drag_and_drop_preview_other.js index 1460a7b6..1d948572 100644 --- a/js/components/ascribe_uploader/file_drag_and_drop_preview_other.js +++ b/js/components/ascribe_uploader/file_drag_and_drop_preview_other.js @@ -4,7 +4,7 @@ import React from 'react'; import ProgressBar from 'react-progressbar'; import AppConstants from '../../constants/application_constants'; -import { getLangText } from '../../utils/lang_utils.js' +import { getLangText } from '../../utils/lang_utils.js'; let FileDragAndDropPreviewOther = React.createClass({ propTypes: { diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index 18961070..90fe7d2c 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -142,7 +142,7 @@ var ReactS3FineUploader = React.createClass({ endpoint: null }, messages: { - unsupportedBrowser: '

Upload is not functional in IE7 as IE7 has no support for CORS!

' + unsupportedBrowser: '

' + getLangText('Upload is not functional in IE7 as IE7 has no support for CORS!') + '

' }, formatFileName: function(name){// fix maybe if (name !== undefined && name.length > 26) { @@ -151,7 +151,7 @@ var ReactS3FineUploader = React.createClass({ return name; }, multiple: false, - defaultErrorMessage: 'Unexpected error. Please contact us if this happens repeatedly.' + defaultErrorMessage: getLangText('Unexpected error. Please contact us if this happens repeatedly.') }; }, @@ -278,7 +278,7 @@ var ReactS3FineUploader = React.createClass({ file.s3Url = res.digitalwork.url_safe; file.s3UrlSafe = res.digitalwork.url_safe; } else { - throw new Error('Could not find a url to download.'); + throw new Error(getLangText('Could not find a url to download.')); } defer.success(res.key); }) @@ -334,7 +334,9 @@ var ReactS3FineUploader = React.createClass({ onValidate(data) { if(data.size > this.props.validation.sizeLimit) { this.state.uploader.cancelAll(); - let notification = new GlobalNotificationModel('Your file is bigger than ' + this.props.validation.sizeLimit / 1000000 + 'MB', 'danger', 5000); + + let fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000; + let notification = new GlobalNotificationModel(getLangText('Your file is bigger than %d MB', fileSizeInMegaBytes), 'danger', 5000); GlobalNotificationActions.appendGlobalNotification(notification); } }, @@ -342,7 +344,7 @@ var ReactS3FineUploader = React.createClass({ onCancel(id) { this.removeFileWithIdFromFilesToUpload(id); - let notification = new GlobalNotificationModel('File upload canceled', 'success', 5000); + let notification = new GlobalNotificationModel(getLangText('File upload canceled'), 'success', 5000); GlobalNotificationActions.appendGlobalNotification(notification); // since the form validation props isReadyForFormSubmission, setIsUploadReady and submitKey @@ -459,7 +461,7 @@ var ReactS3FineUploader = React.createClass({ if(this.state.uploader.pauseUpload(fileId)) { this.setStatusOfFile(fileId, 'paused'); } else { - throw new Error('File upload could not be paused.'); + throw new Error(getLangText('File upload could not be paused.')); } }, @@ -468,7 +470,7 @@ var ReactS3FineUploader = React.createClass({ if(this.state.uploader.continueUpload(fileId)) { this.setStatusOfFile(fileId, 'uploading'); } else { - throw new Error('File upload could not be resumed.'); + throw new Error(getLangText('File upload could not be resumed.')); } }, diff --git a/js/utils/file_utils.js b/js/utils/file_utils.js index 5d4ccd5a..38507d2c 100644 --- a/js/utils/file_utils.js +++ b/js/utils/file_utils.js @@ -37,6 +37,9 @@ export function computeHashOfFile(file) { let fileReader = new FileReader(); let startTime = new Date(); + + // comment: We should convert this to es6 at some point, however if so please consider that + // an arrow function will get rid of the function's scope... fileReader.onload = function(e) { //console.log('read chunk nr', currentChunk + 1, 'of', chunks); spark.append(e.target.result); // Append array buffer