Example #1
0
 def post(self, request):
     form = WordsTranslationsForm(request.POST)
     if form.is_valid():
         words_translations_service.set_word_translations(
             form.cleaned_data['source_word'],
             to_word_model(form.cleaned_data['source_language']),
             form.translation_fields())
     return redirect('translations:words_translations')
Example #2
0
 def auto_tokenize(self):
     """
     Tokenize the business text into words, create their objects
     if necessary and link the business text to them.
     Only applied to Chinese words.
     """
     word_model = to_word_model(self.language)
     if word_model == WordZH:
         tokens = Languages.tokenize(self.language, self.text)
         self.words_zh.clear()
         ordinal = 0
         for token in tokens:
             word_object = word_model.get_or_create_with_translator(word=token)[0]
             BusinessTextWordZH.objects.create(text=self, word=word_object, ordinal=ordinal).save()
             ordinal += 1
Example #3
0
 def post(self, request, *args, **kwargs):
     """
     API for accessing words translations
     """
     source_word_model = to_word_model(request.POST['source_language'])
     operation = request.POST['operation']
     if operation == TranslationsOperation.set_translations.value:
         words_translations_service.set_word_translations(request.POST['source_word'],
                                                          source_word_model,
                                                          json.loads(request.POST['translations']))
         return JsonResponse({})
     elif operation == TranslationsOperation.get_matches.value:
         matches = words_translations_service.get_word_matches(request.POST['source_word'],
                                                               source_word_model)
         return JsonResponse({'matches': matches})
     elif operation == TranslationsOperation.get_translations.value:
         translations = words_translations_service.get_word_translations(request.POST['source_word'],
                                                                         source_word_model)
         return JsonResponse({'translations': translations})
     return HttpResponseBadRequest()