def translate(self): """ Processes a translation request. """ translation_request = request_provider(self._style, request) logging.debug("REQUEST - " + repr(translation_request)) translations = self._translator.translate(translation_request.segments, translation_request.settings) response_data = { 'status': TranslationResponse.STATUS_OK, 'segments': [translation.target_words for translation in translations], 'word_alignments': [ translation.get_alignment_json(as_string=False) for translation in translations ] if translation_request.settings.get_alignment else None, 'word_probabilities': [translation.target_probs for translation in translations] if translation_request.settings.get_word_probs else None, } translation_response = response_provider(self._style, **response_data) logging.debug("RESPONSE - " + repr(translation_response)) response.content_type = translation_response.get_content_type() return repr(translation_response)
def translate(self): """ Processes a translation request. """ translation_request = request_provider(self._style, request) logging.debug("REQUEST - " + repr(translation_request)) translations = self._translator.translate( translation_request.segments, translation_request.settings ) response_data = { 'status': TranslationResponse.STATUS_OK, 'segments': [translation.target_words for translation in translations], } translation_response = response_provider(self._style, **response_data) logging.debug("RESPONSE - " + repr(translation_response)) response.content_type = translation_response.get_content_type() return repr(translation_response)
def translate(self): """ Processes a translation request. """ translation_request = request_provider(self._style, request) logging.debug("REQUEST - " + repr(translation_request)) print(translation_request.settings) translations= self._translator.translate_string( translation_request.segments, translation_request.settings ) # print(translations[0].target_words) response_data = { 'status': TranslationResponse.STATUS_OK, 'segments': " ".join(translations[0].target_words), } translation_response = response_provider(self._style, **response_data) logging.debug("RESPONSE - " + repr(translation_response)) response.content_type = translation_response.get_content_type() return repr(translation_response)