MCPcopy Create free account
hub / github.com/DeepL/deepl-python / translate_document

Method translate_document

deepl/translator.py:686–761  ·  view source on GitHub ↗

Upload document, translate it into the target language, and download result. :param input_document: Document to translate as a file-like object. It is recommended to open files in binary mode. :param output_document: File-like object to receive translated

(
        self,
        input_document: Union[TextIO, BinaryIO, Any],
        output_document: Union[TextIO, BinaryIO, Any],
        *,
        source_lang: Optional[str] = None,
        target_lang: str,
        formality: Union[str, Formality] = Formality.DEFAULT,
        glossary: Union[
            str, GlossaryInfo, MultilingualGlossaryInfo, None
        ] = None,
        filename: Optional[str] = None,
        output_format: Optional[str] = None,
        timeout_s: Optional[int] = None,
        extra_body_parameters: Optional[dict] = None,
    )

Source from the content-addressed store, hash-verified

684 raise e
685
686 def translate_document(
687 self,
688 input_document: Union[TextIO, BinaryIO, Any],
689 output_document: Union[TextIO, BinaryIO, Any],
690 *,
691 source_lang: Optional[str] = None,
692 target_lang: str,
693 formality: Union[str, Formality] = Formality.DEFAULT,
694 glossary: Union[
695 str, GlossaryInfo, MultilingualGlossaryInfo, None
696 ] = None,
697 filename: Optional[str] = None,
698 output_format: Optional[str] = None,
699 timeout_s: Optional[int] = None,
700 extra_body_parameters: Optional[dict] = None,
701 ) -> DocumentStatus:
702 """Upload document, translate it into the target language, and download
703 result.
704
705 :param input_document: Document to translate as a file-like object. It
706 is recommended to open files in binary mode.
707 :param output_document: File-like object to receive translated
708 document.
709 :param source_lang: (Optional) Language code of input document, for
710 example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
711 input language.
712 :param target_lang: Language code to translate document into, for
713 example "DE", "EN-US", "FR".
714 :param formality: (Optional) Desired formality for translation, as
715 Formality enum, "less", "more", "prefer_less", or "prefer_more".
716 :param glossary: (Optional) glossary or glossary ID to use for
717 translation. Must match specified source_lang and target_lang.
718 :param filename: (Optional) Filename including extension, only required
719 if uploading string or bytes containing file content.
720 :param output_format: (Optional) Desired output file extension, if
721 it differs from the input file format.
722 :param timeout_s: (beta) (Optional) Maximum time to wait before
723 the call raises an error. Note that this is not accurate to the
724 second, but only polls every 5 seconds.
725 :param extra_body_parameters: (Optional) Additional key/value pairs to
726 include in the JSON request body sent to the API. If provided,
727 keys in this dict will be added to the request body. Existing
728 keys set by the client will not be overwritten by entries in
729 extra_body_parameters.
730 :return: DocumentStatus when document translation completed, this
731 allows the number of billed characters to be queried.
732
733 :raises DocumentTranslationException: If an error occurs during
734 translation, the exception includes the document handle.
735 """
736
737 handle = self.translate_document_upload(
738 input_document,
739 target_lang=target_lang,
740 source_lang=source_lang,
741 formality=formality,
742 glossary=glossary,
743 filename=filename,

Callers 3

mainFunction · 0.95

Tested by 1