Skip to content

Commit

Permalink
[translation] update samples (Azure#17555)
Browse files Browse the repository at this point in the history
* delete cancel translation job samples

* rename files to fit hero scenarios

* add samples for authenticating the client

* updates for create translation job samples

* updates for document status check samples

* update samples for list jobs

* updates for samples that use azure storage

* updates for samples for glossaries

* fix weird indent on sample headers

* replace references to FR

* remove glossary sample test prefix

* update readme links to samples

* comment out non-live links

* review feedback

* failed at job level won't have error code/message

* missed a rename for translation glossary format -> file_format
  • Loading branch information
kristapratico authored Mar 26, 2021
1 parent b6803a7 commit 19f9aba
Show file tree
Hide file tree
Showing 23 changed files with 1,036 additions and 1,003 deletions.
39 changes: 27 additions & 12 deletions sdk/documenttranslation/azure-ai-documenttranslation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ for job in jobs:
```

To see how to use the Document Translation client library with Azure Storage Blob to upload documents, create SAS tokens
for your containers, and download the finished translated documents, see this [sample][sample_batch_translation_with_storage.py].
for your containers, and download the finished translated documents, see this [sample][sample_translation_with_azure_blob].
Note that you will need to install the [azure-storage-blob][azure_storage_blob] library to run this sample.

## Troubleshooting
Expand Down Expand Up @@ -320,21 +320,25 @@ The following section provides several code snippets illustrating common pattern

These code samples show common scenario operations with the Azure Document Translation client library.

* Client authentication: TODO
* Create a translation job: TODO
* Check the status of documents: TODO
* List all submitted translation jobs: TODO
* Client authentication: [sample_authentication.py][sample_authentication]
* Create a translation job: [sample_create_translation_job.py][sample_create_translation_job]
* Check the status of documents: [sample_check_document_statuses.py][sample_check_document_statuses]
* List all submitted translation jobs: [sample_list_all_submitted_jobs.py][sample_list_all_submitted_jobs]
* Apply a custom glossary to translation: [sample_translation_with_glossaries.py][sample_translation_with_glossaries]
* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob.py][sample_translation_with_azure_blob]


### Async samples
This library also includes a complete async API supported on Python 3.6+. To use it, you must
first install an async transport, such as [aiohttp](https://pypi.org/project/aiohttp/). Async clients
are found under the `azure.ai.documenttranslation.aio` namespace.

* Client authentication: TODO
* Create a translation job: TODO
* Check the status of documents: TODO
* List all submitted translation jobs: TODO
* Client authentication: [sample_authentication_async.py][sample_authentication_async]
* Create a translation job: [sample_create_translation_job_async.py][sample_create_translation_job_async]
* Check the status of documents: [sample_check_document_statuses_async.py][sample_check_document_statuses_async]
* List all submitted translation jobs: [sample_list_all_submitted_jobs_async.py][sample_list_all_submitted_jobs_async]
* Apply a custom glossary to translation: [sample_translation_with_glossaries_async.py][sample_translation_with_glossaries_async]
* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob_async.py][sample_translation_with_azure_blob_async]

### Additional documentation

Expand Down Expand Up @@ -379,9 +383,20 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con

[sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/azure-sdk-logging


[sample_batch_translation_with_storage.py]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_batch_translation_with_storage.py

<!--
[sample_authentication]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_authentication.py
[sample_authentication_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_authentication_async.py
[sample_create_translation_job]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_create_translation_job.py
[sample_create_translation_job_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_create_translation_job_async.py
[sample_check_document_statuses]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_check_document_statuses.py
[sample_check_document_statuses_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_check_document_statuses_async.py
[sample_list_all_submitted_jobs]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_list_all_submitted_jobs.py
[sample_list_all_submitted_jobs_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_list_all_submitted_jobs_async.py
[sample_translation_with_glossaries]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_translation_with_glossaries.py
[sample_translation_with_glossaries_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_translation_with_glossaries_async.py
[sample_translation_with_azure_blob]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/samples/sample_translation_with_azure_blob.py
[sample_translation_with_azure_blob_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/documenttranslation/azure-ai-documenttranslation/async_samples/sample_translation_with_azure_blob_async.py
-->

[cla]: https://cla.microsoft.com
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

"""
FILE: sample_authentication_async.py
DESCRIPTION:
This sample demonstrates how to authenticate to the Document Translation service.
There is currently only one supported method of authentication:
1) Use a Document Translation API key with AzureKeyCredential from azure.core.credentials
Note: the endpoint must be formatted to use the custom domain name for your resource:
https://<NAME-OF-YOUR-RESOURCE>.cognitiveservices.azure.com/
USAGE:
python sample_authentication_async.py
Set the environment variables with your own values before running the sample:
1) AZURE_DOCUMENT_TRANSLATION_ENDPOINT - the endpoint to your Document Translation resource.
2) AZURE_DOCUMENT_TRANSLATION_KEY - your Document Translation API key
"""

import os
import asyncio


async def sample_authentication_api_key_async():
from azure.core.credentials import AzureKeyCredential
from azure.ai.documenttranslation.aio import DocumentTranslationClient

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]

document_translation_client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))

# make calls with authenticated client
async with document_translation_client:
result = await document_translation_client.get_document_formats()


async def main():
await sample_authentication_api_key_async()

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

This file was deleted.

This file was deleted.

Loading

0 comments on commit 19f9aba

Please sign in to comment.