Skip to content

Commit

Permalink
[translation] renames (#19063)
Browse files Browse the repository at this point in the history
* add polling implementation

* add polling generation transforms and regenerate

* add tests and recordings

* samples, readme, changelog

* update changelog

* pylint

* some docs updates

* missed an await

* all the renames

* call it DocumentTranslationLROPoller to align with TA naming

* list_translations -> list_all_translation_statuses
  • Loading branch information
kristapratico authored Jun 4, 2021
1 parent d040674 commit da4057c
Show file tree
Hide file tree
Showing 62 changed files with 958 additions and 957 deletions.
8 changes: 7 additions & 1 deletion sdk/translation/azure-ai-translation-document/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ This version of the SDK defaults to the latest supported service version, which
**Breaking changes**

- `create_translation_job` was removed and replaced with `begin_translation` which follows a long-running operation (LRO)
approach. The client method now returns a `DocumentTranslationPoller` (or `AsyncDocumentTranslationPoller`) to begin the
approach. The client method now returns a `DocumentTranslationLROPoller` (or `AsyncDocumentTranslationLROPoller`) to begin the
long-running operation. A call to `.result()` can be made on the poller object to wait until the translation is complete.
See the [README](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/translation/azure-ai-translation-document/README.md) for more information about LROs.
- Upon completion of the LRO, `begin_translation` now returns a pageable of `DocumentStatusResult`. All job-level metadata can still
be found on `poller.details`.
- `has_completed` has been removed from `JobStatusResult` and `DocumentStatusResult`. Use `poller.done()` to check if the
translation has completed.
- Client method `wait_until_done` has been removed. Use `poller.result()` to wait for the LRO to complete.
- Client method `list_submitted_jobs` has been renamed to `list_all_translation_statuses`.
- Client method `get_job_status` has been renamed to `get_translation_status`.
- Client method `cancel_job` has been renamed to `cancel_translation`.
- Parameter `job_id` was renamed to `translation_id` for `get_translation_status`, `cancel_translation`, `list_all_document_statuses`, and `get_document_status`.
- `JobStatusResult` has been renamed to `TranslationStatusResult`.
- `DocumentStatusResult` property `translate_to` has been renamed to `translated_to`

**New features**

Expand Down
34 changes: 17 additions & 17 deletions sdk/translation/azure-ai-translation-document/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ followed by polling the service at intervals to determine whether the operation
succeeded, to get the result.

Methods that translate documents are modeled as long-running operations.
The client exposes a `begin_<method-name>` method that returns a `DocumentTranslationPoller` or `AsyncDocumentTranslationPoller`. Callers should wait
The client exposes a `begin_<method-name>` method that returns a `DocumentTranslationLROPoller` or `AsyncDocumentTranslationLROPoller`. Callers should wait
for the operation to complete by calling `result()` on the poller object returned from the `begin_<method-name>` method.
Sample code snippets are provided to illustrate using long-running operations [below](#examples "Examples").

Expand Down Expand Up @@ -288,7 +288,7 @@ for document in result:
if document.status == "Succeeded":
print("Source document location: {}".format(document.source_document_url))
print("Translated document location: {}".format(document.translated_document_url))
print("Translated to language: {}\n".format(document.translate_to))
print("Translated to language: {}\n".format(document.translated_to))
else:
print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message))
```
Expand All @@ -305,20 +305,20 @@ credential = AzureKeyCredential("<api_key>")

document_translation_client = DocumentTranslationClient(endpoint, credential)

jobs = document_translation_client.list_submitted_jobs() # type: ItemPaged[JobStatusResult]
operations = document_translation_client.list_all_translation_statuses() # type: ItemPaged[TranslationStatusResult]

for job in jobs:
print("Job ID: {}".format(job.id))
print("Job status: {}".format(job.status))
print("Job created on: {}".format(job.created_on))
print("Job last updated on: {}".format(job.last_updated_on))
print("Total number of translations on documents: {}".format(job.documents_total_count))
print("Total number of characters charged: {}".format(job.total_characters_charged))
for operation in operations:
print("ID: {}".format(operation.id))
print("Status: {}".format(operation.status))
print("Created on: {}".format(operation.created_on))
print("Last updated on: {}".format(operation.last_updated_on))
print("Total number of translations on documents: {}".format(operation.documents_total_count))
print("Total number of characters charged: {}".format(operation.total_characters_charged))

print("Of total documents...")
print("{} failed".format(job.documents_failed_count))
print("{} succeeded".format(job.documents_succeeded_count))
print("{} cancelled".format(job.documents_cancelled_count))
print("{} failed".format(operation.documents_failed_count))
print("{} succeeded".format(operation.documents_succeeded_count))
print("{} cancelled".format(operation.documents_cancelled_count))
```

To see how to use the Document Translation client library with Azure Storage Blob to upload documents, create SAS tokens
Expand Down Expand Up @@ -359,7 +359,7 @@ These code samples show common scenario operations with the Azure Document Trans
* Begin translating documents: [sample_begin_translation.py][sample_begin_translation]
* Translate with multiple inputs: [sample_translate_multiple_inputs.py][sample_translate_multiple_inputs]
* 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]
* List all submitted translation operations: [sample_list_all_translations.py][sample_list_all_translations]
* 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]

Expand All @@ -373,7 +373,7 @@ are found under the `azure.ai.translation.document.aio` namespace.
* Begin translating documents: [sample_begin_translation_async.py][sample_begin_translation_async]
* Translate with multiple inputs: [sample_translate_multiple_inputs_async.py][sample_translate_multiple_inputs_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]
* List all submitted translation operations: [sample_list_all_translations_async.py][sample_list_all_translations_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]

Expand Down Expand Up @@ -432,8 +432,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[sample_translate_multiple_inputs_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translate_multiple_inputs_async.py
[sample_check_document_statuses]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/sample_check_document_statuses.py
[sample_check_document_statuses_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py
[sample_list_all_submitted_jobs]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/sample_list_all_submitted_jobs.py
[sample_list_all_submitted_jobs_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_all_submitted_jobs_async.py
[sample_list_all_translations]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/sample_list_all_translations.py
[sample_list_all_translations_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_all_translations_async.py
[sample_translation_with_glossaries]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_glossaries.py
[sample_translation_with_glossaries_async]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_glossaries_async.py
[sample_translation_with_azure_blob]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_azure_blob.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
StorageInputType,
)
from ._api_version import DocumentTranslationApiVersion
from ._polling import DocumentTranslationPoller
from ._polling import DocumentTranslationLROPoller
from ._models import (
TranslationTarget,
JobStatusResult,
TranslationStatusResult,
DocumentStatusResult,
DocumentTranslationError,
TranslationGlossary,
Expand All @@ -32,8 +32,8 @@
"StorageInputType",
"FileFormat",
"TranslationTarget",
"JobStatusResult",
"TranslationStatusResult",
"DocumentStatusResult",
"DocumentTranslationError",
"DocumentTranslationPoller"
"DocumentTranslationLROPoller"
]
Loading

0 comments on commit da4057c

Please sign in to comment.