Skip to content

Uploading text file yields dorky encoding in the UI. #24

@erip

Description

@erip

I'm trying to pretranslate a list of raw strings. The easiest way to do this using the API seems to be uploading a document with pretranslation options enabled. Unfortunately it seems like submitting .txt files causes issues from the Python client.

My code below:

configuration = lilt.Configuration(
    host = host,
    api_key = {
        'key': api_key
    },
)
with lilt.ApiClient(configuration) as api_client:
    api_instance = lilt.DocumentsApi(api_client)
    name = 'dummy.txt' 
    project_id = 4 
    s = BytesIO("Hello, world!".encode())
    body = s.read() .
    pretranslate = 'tm+mt' 

    try:
        api_response = api_instance.upload_document(name, project_id, body, pretranslate=pretranslate)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TranslateApi->translate_segment: %s\n" % e)

The corresponding uploaded document in UI:

Screen Shot 2021-05-07 at 8 13 19 AM

Perhaps I'm misunderstanding the API as I see the same behavior with cURL:

curl -k -X POST "$host/documents/files?key=$key" \
  --header "LILT-API: {\"name\": \"test2.txt\",\"pretranslate\": \"tm+mt\",\"project_id\": 4}" \
  --header "Content-Type: application/octet-stream" \
  --data-binary @test.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions