Translate alert messages. Switched to `sweetAlert.alert()` instead of raw `window.alert()`.
Override `swal` and `sweetAlert` functions to set translation on default buttons. Changed `sweetAlert()` to `swal()` to be consistent with `mediamanager.js`
This commit is contained in:
parent
1c5ba4438b
commit
3f8d17995a
|
|
@ -52,6 +52,32 @@ $(window).on('ajaxConfirmMessage', function(event, message){
|
|||
return true
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
* Override "Sweet Alert" functions to translate default buttons
|
||||
*/
|
||||
|
||||
$(document).on('ready', function(){
|
||||
if (!window.swal) return
|
||||
|
||||
var swal = window.swal;
|
||||
|
||||
window.sweetAlert = window.swal = function(message, callback) {
|
||||
if(typeof message === 'object') {
|
||||
// Do not override if texts are provided
|
||||
message.confirmButtonText = message.confirmButtonText || $.oc.lang.get('sweetalert.confirm_button_text');
|
||||
message.cancelButtonText = message.cancelButtonText || $.oc.lang.get('sweetalert.cancel_button_text');
|
||||
} else {
|
||||
message = {
|
||||
title: message,
|
||||
confirmButtonText: $.oc.lang.get('sweetalert.confirm_button_text'),
|
||||
cancelButtonText: $.oc.lang.get('sweetalert.cancel_button_text')
|
||||
}
|
||||
}
|
||||
swal(message, callback);
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
* Path helpers
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,12 +52,20 @@ RedactorPlugins.mediamanager = function()
|
|||
cropAndInsertButton: false,
|
||||
onInsert: function(items) {
|
||||
if (!items.length) {
|
||||
alert($.oc.lang.get('mediamanager.invalid_file_empty_insert'))
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_file_empty_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (items.length > 1) {
|
||||
alert($.oc.lang.get('mediamanager.invalid_file_single_insert'))
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_file_single_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +99,11 @@ RedactorPlugins.mediamanager = function()
|
|||
cropAndInsertButton: true,
|
||||
onInsert: function(items) {
|
||||
if (!items.length) {
|
||||
alert('Please select image(s) to insert.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_image_empty_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
that.selection.restore()
|
||||
|
|
@ -104,7 +116,11 @@ RedactorPlugins.mediamanager = function()
|
|||
|
||||
for (var i=0, len=items.length; i<len; i++) {
|
||||
if (items[i].documentType !== 'image') {
|
||||
alert('The file "'+items[i].title+'" is not an image.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_image_invalid_insert', 'The file "'+items[i].title+'" is not an image.'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -154,19 +170,31 @@ RedactorPlugins.mediamanager = function()
|
|||
cropAndInsertButton: false,
|
||||
onInsert: function(items) {
|
||||
if (!items.length) {
|
||||
alert('Please select a video file to insert.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_video_empty_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (items.length > 1) {
|
||||
alert('Please select a single file.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_file_single_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var item = items[0]
|
||||
|
||||
if (item.documentType !== 'video') {
|
||||
alert('The file "'+item.title+'" is not a video.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_video_invalid_insert', 'The file "'+item.title+'" is not a video.'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -201,19 +229,31 @@ RedactorPlugins.mediamanager = function()
|
|||
cropAndInsertButton: false,
|
||||
onInsert: function(items) {
|
||||
if (!items.length) {
|
||||
alert('Please select an audio file to insert.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_audio_empty_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (items.length > 1) {
|
||||
alert('Please select a single file.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_file_single_insert'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var item = items[0]
|
||||
|
||||
if (item.documentType !== 'audio') {
|
||||
alert('The file "'+item.title+'" is not an audio file.')
|
||||
swal({
|
||||
title: $.oc.lang.get('mediamanager.invalid_audio_invalid_insert', 'The file "'+item.title+'" is not an audio file.'),
|
||||
// type: 'error',
|
||||
confirmButtonClass: 'btn-default'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ return [
|
|||
'invalid_file_single_insert' => "Please select a single file.",
|
||||
],
|
||||
|
||||
'sweetalert' => [
|
||||
'confirm_button_text' => 'OK',
|
||||
'cancel_button_text' => 'Cancel',
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,14 +35,24 @@ return [
|
|||
],
|
||||
|
||||
'mediamanager' => [
|
||||
'insert_link' => "Insert Media Link",
|
||||
'insert_image' => "Insert Media Image",
|
||||
'insert_video' => "Insert Media Video",
|
||||
'insert_audio' => "Insert Media Audio",
|
||||
'invalid_file_empty_insert' => "Please select file to insert a links to.",
|
||||
'invalid_file_single_insert' => "Please select a single file.",
|
||||
'insert_link' => "Insérer un lien vers un fichier de la médiathèque",
|
||||
'insert_image' => "Insérer une image de la médiathèque",
|
||||
'insert_video' => "Insérer une vidéo de la médiathèque",
|
||||
'insert_audio' => "Insérer un document audio de la médiathèque",
|
||||
'invalid_file_empty_insert' => "Veuillez sélectionner un fichier à lier.",
|
||||
'invalid_file_single_insert' => "Veuillez sélectionner un seul fichier.",
|
||||
'invalid_image_empty_insert' => "Veuillez sélectionner au moins une image à insérer.",
|
||||
'invalid_video_empty_insert' => "Veuillez sélectionner une vidéo à insérer.",
|
||||
'invalid_audio_empty_insert' => "Veuillez sélectionner un document audio à insérer.",
|
||||
'invalid_image_invalid_insert' => "Le fichier n‘est pas une image.",
|
||||
'invalid_video_invalid_insert' => "Le fichier n‘est pas une vidéo.",
|
||||
'invalid_audio_invalid_insert' => "Le fichier n‘est pas un document audio.",
|
||||
],
|
||||
|
||||
'sweetalert' => [
|
||||
'confirm_button_text' => 'OK',
|
||||
'cancel_button_text' => 'Annuler',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue