added translations
This commit is contained in:
+14
-13
@@ -14,6 +14,7 @@ from django.core import signing
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_date
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_http_methods
|
||||
@@ -239,13 +240,13 @@ def classify_upload(request):
|
||||
|
||||
uploaded_file = request.FILES.get("audio")
|
||||
if not uploaded_file:
|
||||
return _render_error(request, "Choose an audio file before starting the analysis.")
|
||||
return _render_error(request, _("Choose an audio file before starting the analysis."))
|
||||
|
||||
extension = Path(uploaded_file.name).suffix.lower()
|
||||
if not (uploaded_file.content_type or "").startswith("audio/") and extension not in AUDIO_EXTENSIONS:
|
||||
return _render_error(request, "Please upload a supported audio file (such as WAV, MP3, M4A, or OGG).")
|
||||
return _render_error(request, _("Please upload a supported audio file (such as WAV, MP3, M4A, or OGG)."))
|
||||
if uploaded_file.size > MAX_AUDIO_SIZE:
|
||||
return _render_error(request, "This demo accepts audio files up to 25 MiB.")
|
||||
return _render_error(request, _("This demo accepts audio files up to 25 MiB."))
|
||||
|
||||
body, content_type = _encode_audio_multipart(uploaded_file)
|
||||
classifier_request = Request(
|
||||
@@ -259,14 +260,14 @@ def classify_upload(request):
|
||||
with urlopen(classifier_request, timeout=60) as response:
|
||||
payload = json.loads(response.read().decode("utf-8"))
|
||||
except HTTPError as error:
|
||||
return _render_error(request, f"The classifier returned an error (HTTP {error.code}).", status=502)
|
||||
return _render_error(request, _("The classifier returned an error (HTTP %(code)s).") % {"code": error.code}, status=502)
|
||||
except (URLError, TimeoutError):
|
||||
return _render_error(request, "The classifier could not be reached. Please try again shortly.", status=502)
|
||||
return _render_error(request, _("The classifier could not be reached. Please try again shortly."), status=502)
|
||||
except json.JSONDecodeError:
|
||||
return _render_error(request, "The classifier returned an unreadable response.", status=502)
|
||||
return _render_error(request, _("The classifier returned an unreadable response."), status=502)
|
||||
|
||||
if not isinstance(payload, dict):
|
||||
return _render_error(request, "The classifier returned an unexpected response.", status=502)
|
||||
return _render_error(request, _("The classifier returned an unexpected response."), status=502)
|
||||
|
||||
# Keep the raw payload in this request flow; this is the future hand-off point
|
||||
# for saving the upload and its classification to a database or queue.
|
||||
@@ -281,17 +282,17 @@ def submit_pending_event(request):
|
||||
uploaded_file = request.FILES.get("audio")
|
||||
token = request.POST.get("classification_token")
|
||||
if not uploaded_file:
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": "Keep the analysed audio file selected before submitting it for review."}, status=400)
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": _("Keep the analysed audio file selected before submitting it for review.")}, status=400)
|
||||
if not token:
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": "Analyse the file before submitting it for review."}, status=400)
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": _("Analyse the file before submitting it for review.")}, status=400)
|
||||
|
||||
try:
|
||||
payload = signing.loads(token, salt="fireworks_detect.classification", max_age=60 * 60)
|
||||
except signing.BadSignature:
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": "This analysis has expired. Please analyse the audio again."}, status=400)
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": _("This analysis has expired. Please analyse the audio again.")}, status=400)
|
||||
|
||||
if not isinstance(payload, dict):
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": "The saved analysis is not valid."}, status=400)
|
||||
return render(request, "fireworks_detect/pending_submission.html", {"error": _("The saved analysis is not valid.")}, status=400)
|
||||
|
||||
pending = PendingEvent.objects.create(
|
||||
audio_file=uploaded_file,
|
||||
@@ -341,7 +342,7 @@ def submit_manual_pending_event(request):
|
||||
return render(
|
||||
request,
|
||||
"fireworks_detect/manual_pending_submission.html",
|
||||
{"error": "Choose between 1 and 1,000 occurrences."},
|
||||
{"error": _("Choose between 1 and 1,000 occurrences.")},
|
||||
status=400,
|
||||
)
|
||||
|
||||
@@ -379,7 +380,7 @@ def event_detail(request, event_id):
|
||||
|
||||
def _audio_response(record):
|
||||
if not record.audio_file:
|
||||
raise Http404("No audio is attached to this record.")
|
||||
raise Http404(_("No audio is attached to this record."))
|
||||
content_type = mimetypes.guess_type(record.audio_file.name)[0] or "application/octet-stream"
|
||||
return FileResponse(record.audio_file.open("rb"), content_type=content_type)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user