Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeepL API: "Failed to open the uploaded document" Error When Translating XLIFF File #63

Open
rgutt opened this issue Feb 13, 2025 · 0 comments

Comments

@rgutt
Copy link

rgutt commented Feb 13, 2025

Describe the bug
Describe the bug When attempting to translate an XLIFF file using the DeepL API with the provided code, the process fails, returning the error message:

{"document_id":"943F2A850142C982DB783AFB069BC892","status":"error","error_message":"Failed to open the uploaded document.","message":"Failed to open the uploaded document."}

To Reproduce
Steps to reproduce the behavior:

  1. Prepare an XLIFF file (input.xlf) with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.1" version="2.1" srcLang="en" trgLang="es">
    <file id="f1" original="example.html">
        <unit id="u1">
            <segment id="s1">
                <source>Hello, world!</source>
            </segment>
        </unit>
    </file>
</xliff>
  1. Use the following Node.js code to initiate the translation:
import * as deepl from 'deepl-node';
import fs from 'fs';

const authKey = 'your-auth-key';
const translator = new deepl.Translator(authKey);
async function translateXLF() {
    const inputFile = 'input.xlf'; 
    const outputFile = 'output.xlf';

    try {
        await translator.translateDocument(
            inputFile,
            outputFile,
            'en',
            'es',
            {
                formality: 'default',
            }
        );
        console.log('Translation completed successfully.');
    } catch (error) {
        if (error.documentHandle) {
            console.error(`Document ID: ${error.documentHandle.documentId}, Document key: ${error.documentHandle.documentKey}`);
        } else {
            console.error(`Error occurred during document translation: ${error.message}`);
        }
    }
}


translateXLF();
3. Execute the script.
node index.js

  1. Observe the error message in the console output.
Request to DeepL API POST /v2/document
Request details: target_lang=es&source_lang=en&formality=default
DeepL API response POST /v2/document 200
Response details:, content = {"document_id":"XXX","document_key":"YYY"}
Request to DeepL API POST /v2/document/XXX
Request details: document_key=YYY
DeepL API response POST /v2/document/XXX 200
Response details:, content = {"document_id":"XXX","status":"error","error_message":"Failed to open the uploaded document.","message":"Failed to open the uploaded document."}

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser Not applicable
  • Version: Node.js 22.3.0

Additional context
The error message "Failed to open the uploaded document" suggests that the DeepL API is unable to process the provided XLIFF file. Using the same script i'm able to translate .docx and .txt files by replacing the input file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant