@@ -153,13 +153,13 @@ def sample_single_document_translation():
153153
154154 # absolute path to your document
155155 file_path = " C:/{your-file-path}/document-translation-sample.docx"
156- file_name = os.path.path. basename(file_path)
156+ file_name = os.path.basename(file_path)
157157 file_type = (
158158 " application/vnd.openxmlformats-officedocument.wordprocessingml.document"
159159 )
160160 print (f " File for translation: { file_name} " )
161161
162- with open (file_name , " r " ) as file :
162+ with open (file_path , " rb " ) as file :
163163 file_contents = file .read()
164164
165165 document_content = (file_name, file_contents, file_type)
@@ -168,8 +168,12 @@ def sample_single_document_translation():
168168 response_stream = client.document_translate(
169169 body = document_translate_content, target_language = target_language
170170 )
171- translated_response = response_stream.decode(" utf-8-sig" ) # type: ignore [ attr -defined ]
172- print (f " Translated response: { translated_response} " )
171+ # Save the response_stream to a file
172+ output_file_path = " ./translated-document.docx"
173+ with open (output_file_path, " wb" ) as output_file:
174+ output_file.write(response_stream)
175+
176+ print (f " Translated document saved to: { output_file_path} " )
173177
174178
175179if __name__ == " __main__" :
0 commit comments