Skip to content

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

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

Open
erip opened this issue May 7, 2021 · 1 comment
Open

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

erip opened this issue May 7, 2021 · 1 comment

Comments

@erip
Copy link

erip commented May 7, 2021

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
@erip
Copy link
Author

erip commented May 7, 2021

Indeed, this doesn't work through the UI either. ☹️

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