diff --git a/DependencyInjection/IrsteaFileUploadExtension.php b/DependencyInjection/IrsteaFileUploadExtension.php index f8ff6ebaf38aa3186c2b0829d782b7f016477127..96359cfb3bc7d64cc3d42b5275fd6ffa06366253 100644 --- a/DependencyInjection/IrsteaFileUploadExtension.php +++ b/DependencyInjection/IrsteaFileUploadExtension.php @@ -48,6 +48,7 @@ class IrsteaFileUploadExtension extends Extension implements PrependExtensionInt "$pluginDir/js/jquery.fileupload-validate.js", "$pluginDir/js/jquery.fileupload-ui.js", "@BazingaJsTranslationBundle/Resources/js/translator.js", + 'js/translations/file_upload/*.js', '@IrsteaFileUploadBundle/Resources/js/widget/file_upload.js' ], ], diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js index b416a30603c0a019ceb17b13c9de875aa69d27f8..2fd78ee2e3cc9ebcf726ceefd420447e0ed09bf4 100644 --- a/Resources/js/widget/file_upload.js +++ b/Resources/js/widget/file_upload.js @@ -2,19 +2,23 @@ * Copyright (C) 2015 IRSTEA * All rights reserved. */ -(function($) { +(function($, Translator) { var formatFileSize = function(size) { + var unit; if(size > 1000000000) { - return (size/1000000000).toFixed(2) + ' Gio'; + size = (size/1000000000).toFixed(2); + unit = 'Gi'; + } else if(size > 1000000) { + size = (size/1000000).toFixed(2); + unit = 'Mi'; + } else if(size > 1000) { + size = (size/1000).toFixed(2); + unit ='Ki'; + } else { + unit = ''; } - if(size > 1000000) { - return (size/1000000).toFixed(2) + ' Mio'; - } - if(size > 1000) { - return (size/1000).toFixed(2)+ ' Kio'; - } - return size + ' o'; + return Translator.trans('file_size(%size%,%unit%)', {size:size, unit:unit}, 'file_upload'); }, formatBitrate = function(rate) { return formatFileSize(rate) + '/s'; @@ -48,7 +52,7 @@ var showError = function(entry, message) { var $this = $(entry); if(message) { - $this.find('.error').text(message); + $this.find('.error').text(Translator.trans(message)); } $this.addClass('alert alert-danger'); $this.find('.error').show(); @@ -84,6 +88,7 @@ downloadTemplateId: null, filesContainer: $this.find('.fileinput-entries'), dropZone: $this, + i18n: Translator.trans, uploadTemplate: function(data) { var rows = $(); $.each(data.files, function (index, file) { @@ -186,4 +191,4 @@ }; -})(jQuery); +})(jQuery, Translator); diff --git a/Resources/less/file_upload.less b/Resources/less/file_upload.less index 8a942873465aeff080e5a3203330de2aa9e6798d..2c76b95430cad9cf2c2144219b52477c1e45a773 100644 --- a/Resources/less/file_upload.less +++ b/Resources/less/file_upload.less @@ -6,15 +6,15 @@ All rights reserved. @import "variables.less"; .fileinput-entry { - & > * { - margin: 0 0.2em; + .cancel, .delete { + margin-left: 0.2em; } .description { display: inline; width: auto; height: auto; padding: @padding-xs-vertical @padding-xs-horizontal; - //margin: 0; + margin: 0 0.2em; } .progress { height: (@line-height-computed / 2); @@ -34,6 +34,9 @@ All rights reserved. } .error { display: inline; + &:after { + content: "."; + } } .size, .description { display: none; @@ -49,3 +52,8 @@ All rights reserved. height: auto !important; min-height: @input-height-base; } + +.template-upload .size { + &:before { content: "("; } + &:after { content: ")"; } +} diff --git a/Resources/translations/file_upload.fr.yml b/Resources/translations/file_upload.fr.yml new file mode 100644 index 0000000000000000000000000000000000000000..c60741ff01914328a5a1e05e5d61d5d4380997b9 --- /dev/null +++ b/Resources/translations/file_upload.fr.yml @@ -0,0 +1,18 @@ +form: + description.placeholder: Description facultative + max_number_of_files(%num%): %num% fichiers maximum + min_file_size: Taille minimale + max_file_size: Taille maximale + +file_size(%size%,%unit%): %size% %unit%o + +# Message d'erreurs du plugin +unknownError: Erreur inconnue +maxNumberOfFiles: Nombre maximum de fichiers dépassé +acceptFileTypes: Type de fichier non autorisé +maxFileSize: Le fichier est trop grand +minFileSize: Le fichier est trop petit + +# Messages d'erreur du serveur +"Invalid CSRF Token": Token CSRF invalide, veuillez recharger la page. +"Internal server error": Erreur interne du serveur diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 4a06d254c94f3591f6777528bb588bd814aa157c..bdbe1a71211153dce22ae1037e90b7618debb097 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -1,12 +1,2 @@ button.upload: Ajouter un fichier - -form: - file_upload: - description.placeholder: Description facultative - max_number_of_files(%num%): %num% fichiers maximum - min_file_size: Taille minimale - max_file_size: Taille maximale - -file_upload: - file_size(%size%,%unit%): %size% %unit%o diff --git a/Resources/views/Form/file_upload.html.twig b/Resources/views/Form/file_upload.html.twig index 054275735299c849c6a2e0c4696f5edb2ca2dbba..5d32376d84b5ba05c742bbe0d7a11f9447e2f350 100644 --- a/Resources/views/Form/file_upload.html.twig +++ b/Resources/views/Form/file_upload.html.twig @@ -19,7 +19,7 @@ <div class="template-download fileinput-entry"> <input class="id" type="hidden" name="{{ full_name }}{% if multiple %}[{{index|default('__index__')}}]{% endif %}[id]" value="{{ file.id|default }}"/> {{ irstea_uploaded_file(file) }} - <input class="form-control description" type="text" placeholder="{% trans %}form.file_upload.description.placeholder{% endtrans %}" name="{{ full_name }}{% if multiple %}[{{index|default('__index__')}}]{% endif %}[description]" value="{{ file.description|default }}"/> + <input class="form-control description" type="text" placeholder="{% trans from 'file_upload' %}form.description.placeholder{% endtrans %}" name="{{ full_name }}{% if multiple %}[{{index|default('__index__')}}]{% endif %}[description]" value="{{ file.description|default }}"/> <span class="error"></span> <a href="#" class="danger delete {%- if disabled or read_only %} disabled{% endif -%}" title="{% trans %}button.delete{% endtrans %}"> {{- irstea_icon('remove') -}} @@ -55,13 +55,13 @@ /> </div> {% if multiple and widget_attr["data-max-number-of-files"] is defined %} - <small>{% trans with {"%num%": widget_attr["data-max-number-of-files"]}%}form.file_upload.max_number_of_files(%num%){% endtrans %}.</small> + <small>{% trans with {"%num%": widget_attr["data-max-number-of-files"]} from 'file_upload' %}form.max_number_of_files(%num%){% endtrans %}.</small> {% endif %} {% if widget_attr["data-min-file-size"] is defined %} - <small>{% trans %}form.file_upload.min_file_size{% endtrans %} : {{ widget_attr["data-min-file-size"]|irstea_file_size(0) }}</small> + <small>{% trans from 'file_upload' %}form.min_file_size{% endtrans %} : {{ widget_attr["data-min-file-size"]|irstea_file_size(0) }}</small> {% endif %} {% if widget_attr["data-max-file-size"] is defined %} - <small>{% trans %}form.file_upload.max_file_size{% endtrans %} : {{ widget_attr["data-max-file-size"]|irstea_file_size(0) }}</small> + <small>{% trans from 'file_upload' %}form.max_file_size{% endtrans %} : {{ widget_attr["data-max-file-size"]|irstea_file_size(0) }}</small> {% endif %} </div> {% endblock file_upload_widget %} diff --git a/Twig/FileUploadExtension.php b/Twig/FileUploadExtension.php index bd680f86bd68655941293d6a33eb0535832b383f..e7ffb8afd6c96c35c641701c48c5bce3d9489848 100644 --- a/Twig/FileUploadExtension.php +++ b/Twig/FileUploadExtension.php @@ -124,12 +124,12 @@ class FileUploadExtension extends Twig_Extension $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, null !== $precision ? $precision : $defaultPrecision); return $this->translator->trans( - 'file_upload.file_size(%size%,%unit%)', + 'file_size(%size%,%unit%)', [ '%size%' => $formatter->format($size), '%unit%' => $unit, ], - null, + 'file_upload', $locale ); }