Beispiel #1
0
 def post(self, request):
     form = TextsTranslationsForm(request.POST)
     if form.is_valid():
         texts_translations_service.set_text_translations(
             form.cleaned_data['source_text'],
             Languages.from_string(form.cleaned_data['source_language']),
             form.translation_fields())
     return redirect('translations:texts_translations')
Beispiel #2
0
 def post(self, request):
     """
     API for accessing text translations
     """
     source_language = Languages.from_string(request.POST['source_language'])
     source_text = request.POST['source_text']
     operation = request.POST['operation']
     if operation == TranslationsOperation.get_matches.value:
         text_matches = texts_translations_service.get_text_matches(source_text, source_language)
         return JsonResponse({'matches': list(text_matches)})
     elif operation == TranslationsOperation.get_translations.value:
         translations = texts_translations_service.get_text_translations(source_text, source_language)
         return JsonResponse({'translations': translations})
     return HttpResponseBadRequest()