diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 520a2c8dd721..906369d1ecc7 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -58,7 +58,7 @@ com.azure:azure-ai-speech-transcription;1.0.0;1.1.0-beta.1 com.azure:azure-ai-textanalytics;5.5.13;5.6.0-beta.1 com.azure:azure-ai-textanalytics-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-ai-translation-text;2.0.0;2.1.0-beta.1 -com.azure:azure-ai-translation-document;1.0.8;1.1.0-beta.1 +com.azure:azure-ai-translation-document;1.0.8;2.0.0 com.azure:azure-ai-vision-face;1.0.0-beta.2;1.0.0-beta.3 com.azure:azure-ai-voicelive;1.0.0;1.1.0-beta.2 com.azure:azure-analytics-defender-easm;1.0.0-beta.1;1.0.0-beta.2 diff --git a/sdk/translation/azure-ai-translation-document/CHANGELOG.md b/sdk/translation/azure-ai-translation-document/CHANGELOG.md index 6dfdafe107a6..58954a810739 100644 --- a/sdk/translation/azure-ai-translation-document/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-document/CHANGELOG.md @@ -1,14 +1,24 @@ # Release History -## 1.1.0-beta.1 (Unreleased) +## 2.0.0 (2026-07-06) ### Features Added -### Breaking Changes +- Added support for the `2026-03-01` service API version, which is now the default. +- Added image translation support: + - Added the `BatchOptions` model with the `translateTextWithinImage` property, and the `options` property on `TranslationBatch`, to enable translation of text embedded within images for batch requests. + - Added `beginTranslation(List, Boolean)` convenience overloads to `DocumentTranslationClient` and `DocumentTranslationAsyncClient` to enable batch image translation without constructing a `TranslationBatch`/`BatchOptions`. + - Added the `translateTextWithinImage` parameter to `SingleDocumentTranslationClient.translate` and `SingleDocumentTranslationAsyncClient.translate` for single document requests. + - Added image scan reporting to `DocumentStatusResult`: `imageCharacterDetected`, `imageCharged`, `totalImageScansSucceeded`, and `totalImageScansFailed`. + - Added image scan totals to `TranslationStatusSummary`: `totalImageScansSucceeded`, `totalImageScansFailed`, and `totalImagesChargedCount`. +- Added custom translation model support: + - Added the `deploymentName` property to `TranslationTarget` to specify the deployment name of the custom translation model for a batch translation request. + - Added the `deploymentName` property to `DocumentStatusResult`, exposing the deployment name of the custom translation model used for the translation. + - Added the `deploymentName` parameter to `SingleDocumentTranslationClient.translate` and `SingleDocumentTranslationAsyncClient.translate` for single document translation requests. -### Bugs Fixed +### Breaking Changes -### Other Changes +- Replaced the `SingleDocumentTranslationClient.translate` and `SingleDocumentTranslationAsyncClient.translate` convenience overload `translate(String, DocumentTranslateContent, String, String, Boolean)` with `translate(String, DocumentTranslateContent, String, String, String, Boolean, Boolean)`, adding the `deploymentName` and `translateTextWithinImage` parameters (positioned after `category` and `allowFallback` respectively). Existing callers of the previous overload must update their call sites to the new signature. ## 1.0.8 (2026-05-05) diff --git a/sdk/translation/azure-ai-translation-document/README.md b/sdk/translation/azure-ai-translation-document/README.md index a34c6640871c..a9993ac3c357 100644 --- a/sdk/translation/azure-ai-translation-document/README.md +++ b/sdk/translation/azure-ai-translation-document/README.md @@ -28,7 +28,7 @@ Various documentation is available to help you get started com.azure azure-ai-translation-document - 1.1.0-beta.1 + 2.0.0 ``` [//]: # ({x-version-update-end}) @@ -190,6 +190,72 @@ System.out.println("Translated Response: " + translatedResponse); ``` Please refer to the service documentation for a conceptual discussion of [singleDocumentTranslation][singleDocumentTranslation_doc]. +### Custom Model Translation +Translate documents with a custom translation model by providing its deployment name. Set the `deploymentName` on the `TranslationTarget` for batch translation; for single document translation pass the `deploymentName` parameter. The deployment name that was used is reported back on each document's status. + +```java startDocumentTranslationWithCustomModel +String sourceUrl = "https://myblob.blob.core.windows.net/sourceContainer"; +TranslationSource translationSource = new TranslationSource(sourceUrl); +translationSource.setLanguage("en"); +translationSource.setStorageSource(TranslationStorageSource.AZURE_BLOB); + +String targetUrl = "https://myblob.blob.core.windows.net/destinationContainer"; +TranslationTarget translationTarget = new TranslationTarget(targetUrl, "es"); +// Set the deployment name of your custom translation model on the target. +translationTarget.setDeploymentName(""); +translationTarget.setStorageSource(TranslationStorageSource.AZURE_BLOB); + +List translationTargets = new ArrayList<>(); +translationTargets.add(translationTarget); + +DocumentTranslationInput batchRequest = new DocumentTranslationInput(translationSource, translationTargets); + +SyncPoller poller = documentTranslationClient + .beginTranslation(TestHelper.getStartTranslationDetails(batchRequest)); +TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); + +for (DocumentStatusResult document : documentTranslationClient.listDocumentStatuses(translationStatus.getId())) { + System.out.println("Document Id: " + document.getId()); + System.out.println("Document Status: " + document.getStatus()); + // The status reports the deployment name of the custom model that was used. + System.out.println("Deployment name used: " + document.getDeploymentName()); +} +``` + +### Image Translation +Translate text that is embedded within images in your documents by enabling `translateTextWithinImage` through `BatchOptions` when starting a batch translation. When enabled, each document's status also reports image scan usage. + +```java startDocumentTranslationWithImageTranslation +String sourceUrl = "https://myblob.blob.core.windows.net/sourceContainer"; +TranslationSource translationSource = new TranslationSource(sourceUrl); +translationSource.setLanguage("en"); +translationSource.setStorageSource(TranslationStorageSource.AZURE_BLOB); + +String targetUrl = "https://myblob.blob.core.windows.net/destinationContainer"; +TranslationTarget translationTarget = new TranslationTarget(targetUrl, "es"); +translationTarget.setStorageSource(TranslationStorageSource.AZURE_BLOB); + +List translationTargets = new ArrayList<>(); +translationTargets.add(translationTarget); + +DocumentTranslationInput batchRequest = new DocumentTranslationInput(translationSource, translationTargets); + +// Enable translation of text embedded within images for the batch using the convenience overload. +SyncPoller poller + = documentTranslationClient.beginTranslation(Arrays.asList(batchRequest), true); +TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); + +for (DocumentStatusResult document : documentTranslationClient.listDocumentStatuses(translationStatus.getId())) { + System.out.println("Document Id: " + document.getId()); + System.out.println("Document Status: " + document.getStatus()); + // Image scan usage is reported when image translation is enabled. + System.out.println("Total image scans succeeded: " + document.getTotalImageScansSucceeded()); + System.out.println("Total image scans failed: " + document.getTotalImageScansFailed()); + System.out.println("Images charged: " + document.getImageCharged()); + System.out.println("Characters detected within images: " + document.getImageCharacterDetected()); +} +``` + ### Cancel Translation Cancels a translation job that is currently processing or queued (pending) as indicated in the request by the id query parameter. @@ -466,6 +532,8 @@ Samples are provided for each main functional area. * [BatchDocumentTranslation][sample_batchDocumentTranslation] * [SingleDocumentTranslation][sample_singleDocumentTranslation] +* [CustomModelTranslation][sample_customModelTranslation] +* [ImageTranslation][sample_imageTranslation] * [CancelTranslation][sample_cancelTranslation] * [GetTranslationsStatus][sample_getTranslationsStatus] * [GetTranslationStatus][sample_getTranslationStatus] @@ -504,6 +572,8 @@ For details on contributing to this repository, see the [contributing guide](htt [single_document_translator_client_class]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java [sample_batchDocumentTranslation]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/StartDocumentTranslation.java [sample_singleDocumentTranslation]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/StartSingleDocumentTranslation.java +[sample_customModelTranslation]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithCustomModel.java +[sample_imageTranslation]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithImageTranslation.java [sample_cancelTranslation]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/CancelDocumentTranslation.java [sample_getTranslationsStatus]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/GetTranslationsStatus.java [sample_getTranslationStatus]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/GetTranslationStatus.java diff --git a/sdk/translation/azure-ai-translation-document/assets.json b/sdk/translation/azure-ai-translation-document/assets.json index b04e81642271..e51b2f80389e 100644 --- a/sdk/translation/azure-ai-translation-document/assets.json +++ b/sdk/translation/azure-ai-translation-document/assets.json @@ -2,5 +2,5 @@ "AssetsRepo" : "Azure/azure-sdk-assets", "AssetsRepoPrefixPath" : "java", "TagPrefix" : "java/translation/azure-ai-translation-document", - "Tag" : "java/translation/azure-ai-translation-document_32dd6be902" + "Tag" : "java/translation/azure-ai-translation-document_52b0493f69" } \ No newline at end of file diff --git a/sdk/translation/azure-ai-translation-document/pom.xml b/sdk/translation/azure-ai-translation-document/pom.xml index ead85587cd08..54e41ac1e335 100644 --- a/sdk/translation/azure-ai-translation-document/pom.xml +++ b/sdk/translation/azure-ai-translation-document/pom.xml @@ -14,7 +14,7 @@ Code generated by Microsoft (R) TypeSpec Code Generator. com.azure azure-ai-translation-document - 1.1.0-beta.1 + 2.0.0 Microsoft Azure SDK for DocumentTranslation This package contains Microsoft Azure DocumentTranslation client library. diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java index 26dbf6bde414..4512e076e619 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java @@ -5,7 +5,9 @@ import com.azure.ai.translation.document.implementation.DocumentTranslationClientImpl; import com.azure.ai.translation.document.implementation.models.SupportedFileFormats; +import com.azure.ai.translation.document.models.BatchOptions; import com.azure.ai.translation.document.models.DocumentStatusResult; +import com.azure.ai.translation.document.models.DocumentTranslationInput; import com.azure.ai.translation.document.models.FileFormat; import com.azure.ai.translation.document.models.FileFormatType; import com.azure.ai.translation.document.models.ListDocumentStatusesOptions; @@ -95,6 +97,7 @@ public final class DocumentTranslationAsyncClient { * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -110,6 +113,9 @@ public final class DocumentTranslationAsyncClient { * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -260,6 +266,9 @@ public PollerFlux beginTranslation(BinaryData body, Requ * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -308,6 +317,11 @@ public PagedFlux listTranslationStatuses(RequestOptions requestOptio * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -363,6 +377,9 @@ public Mono> getDocumentStatusWithResponse(String translati * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -422,6 +439,9 @@ public Mono> getTranslationStatusWithResponse(String transl * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -565,6 +585,11 @@ public Mono> cancelTranslationWithResponse(String translati * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -676,6 +701,35 @@ public PollerFlux beginTransla return serviceClient.beginTranslationWithModelAsync(BinaryData.fromObject(body), requestOptions); } + /** + * Submit a document translation request to the Document Translation service, optionally translating text + * embedded within images in the documents. + * + * This is a convenience overload that enables image translation without constructing a {@link BatchOptions}. + * It builds a {@link TranslationBatch} from the provided inputs and, when {@code translateTextWithinImage} is + * non-null, sets it via {@link BatchOptions#setTranslateTextWithinImage(Boolean)}. + * + * @param inputs the input list of documents or folders containing documents to be translated. + * @param translateTextWithinImage whether to translate text embedded within images in the documents; may be + * {@code null} to use the service default. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux + beginTranslation(List inputs, Boolean translateTextWithinImage) { + TranslationBatch body = new TranslationBatch(inputs); + if (translateTextWithinImage != null) { + body.setOptions(new BatchOptions().setTranslateTextWithinImage(translateTextWithinImage)); + } + return beginTranslation(body); + } + /** * Returns a list of batch requests submitted and the status for each request * diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java index 252ffc3baf39..d30bed9d72da 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java @@ -5,7 +5,9 @@ import com.azure.ai.translation.document.implementation.DocumentTranslationClientImpl; import com.azure.ai.translation.document.implementation.models.SupportedFileFormats; +import com.azure.ai.translation.document.models.BatchOptions; import com.azure.ai.translation.document.models.DocumentStatusResult; +import com.azure.ai.translation.document.models.DocumentTranslationInput; import com.azure.ai.translation.document.models.FileFormat; import com.azure.ai.translation.document.models.FileFormatType; import com.azure.ai.translation.document.models.ListDocumentStatusesOptions; @@ -90,6 +92,7 @@ public final class DocumentTranslationClient { * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -105,6 +108,9 @@ public final class DocumentTranslationClient { * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -255,6 +261,9 @@ public SyncPoller beginTranslation(BinaryData body, Requ * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -303,6 +312,11 @@ public PagedIterable listTranslationStatuses(RequestOptions requestO * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -358,6 +372,9 @@ public Response getDocumentStatusWithResponse(String translationId, * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -416,6 +433,9 @@ public Response getTranslationStatusWithResponse(String translationI * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -558,6 +578,11 @@ public Response cancelTranslationWithResponse(String translationId, * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -669,6 +694,35 @@ public SyncPoller beginTransla return serviceClient.beginTranslationWithModel(BinaryData.fromObject(body), requestOptions); } + /** + * Submit a document translation request to the Document Translation service, optionally translating text + * embedded within images in the documents. + * + * This is a convenience overload that enables image translation without constructing a {@link BatchOptions}. + * It builds a {@link TranslationBatch} from the provided inputs and, when {@code translateTextWithinImage} is + * non-null, sets it via {@link BatchOptions#setTranslateTextWithinImage(Boolean)}. + * + * @param inputs the input list of documents or folders containing documents to be translated. + * @param translateTextWithinImage whether to translate text embedded within images in the documents; may be + * {@code null} to use the service default. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of long-running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller + beginTranslation(List inputs, Boolean translateTextWithinImage) { + TranslationBatch body = new TranslationBatch(inputs); + if (translateTextWithinImage != null) { + body.setOptions(new BatchOptions().setTranslateTextWithinImage(translateTextWithinImage)); + } + return beginTranslation(body); + } + /** * Returns a list of batch requests submitted and the status for each request * diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java index 39dbf3cbc600..6d40420e9e88 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java @@ -13,7 +13,12 @@ public enum DocumentTranslationServiceVersion implements ServiceVersion { /** * Enum value 2024-05-01. */ - V2024_05_01("2024-05-01"); + V2024_05_01("2024-05-01"), + + /** + * Enum value 2026-03-01. + */ + V2026_03_01("2026-03-01"); private final String version; @@ -35,6 +40,6 @@ public String getVersion() { * @return The latest {@link DocumentTranslationServiceVersion}. */ public static DocumentTranslationServiceVersion getLatest() { - return V2024_05_01; + return V2026_03_01; } } diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java index 6901a0abe714..0b6808f5c7dd 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java @@ -56,9 +56,13 @@ public final class SingleDocumentTranslationAsyncClient { * This parameter is used to get translations * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator * project details to this parameter to use your deployed customized system. Default value is: general. + * deploymentNameStringNoDeployment name of the custom translation model for the + * translation request. * allowFallbackBooleanNoSpecifies that the service is allowed to fall back to a * general system when a custom system doesn't exist. * Possible values are: true (default) or false. + * translateTextWithinImageBooleanNoOptional boolean parameter to translate text + * within an image in the document * * You can add these to a request with {@link RequestOptions#addQueryParam} *

Response Body Schema

@@ -98,16 +102,6 @@ Mono> translateWithResponse(String targetLanguage, BinaryDa * The target language must be one of the supported languages included in the translation scope. * For example if you want to translate the document in German language, then use targetLanguage=de. * @param documentTranslateContent Document Translate Request Content. - * @param sourceLanguage Specifies source language of the input document. - * If this parameter isn't specified, automatic language detection is applied to determine the source language. - * For example if the source document is written in English, then use sourceLanguage=en. - * @param category A string specifying the category (domain) of the translation. This parameter is used to get - * translations - * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator - * project details to this parameter to use your deployed customized system. Default value is: general. - * @param allowFallback Specifies that the service is allowed to fall back to a general system when a custom system - * doesn't exist. - * Possible values are: true (default) or false. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. @@ -118,19 +112,9 @@ Mono> translateWithResponse(String targetLanguage, BinaryDa */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono translate(String targetLanguage, DocumentTranslateContent documentTranslateContent, - String sourceLanguage, String category, Boolean allowFallback) { + public Mono translate(String targetLanguage, DocumentTranslateContent documentTranslateContent) { // Generated convenience method for translateWithResponse RequestOptions requestOptions = new RequestOptions(); - if (sourceLanguage != null) { - requestOptions.addQueryParam("sourceLanguage", sourceLanguage, false); - } - if (category != null) { - requestOptions.addQueryParam("category", category, false); - } - if (allowFallback != null) { - requestOptions.addQueryParam("allowFallback", String.valueOf(allowFallback), false); - } return translateWithResponse(targetLanguage, new MultipartFormDataHelper(requestOptions) .serializeFileField("document", documentTranslateContent.getDocument().getContent(), @@ -169,6 +153,18 @@ public Mono translate(String targetLanguage, DocumentTranslateConten * The target language must be one of the supported languages included in the translation scope. * For example if you want to translate the document in German language, then use targetLanguage=de. * @param documentTranslateContent Document Translate Request Content. + * @param sourceLanguage Specifies source language of the input document. + * If this parameter isn't specified, automatic language detection is applied to determine the source language. + * For example if the source document is written in English, then use sourceLanguage=en. + * @param category A string specifying the category (domain) of the translation. This parameter is used to get + * translations + * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator + * project details to this parameter to use your deployed customized system. Default value is: general. + * @param deploymentName Deployment name of the custom translation model for the translation request. + * @param allowFallback Specifies that the service is allowed to fall back to a general system when a custom system + * doesn't exist. + * Possible values are: true (default) or false. + * @param translateTextWithinImage Optional boolean parameter to translate text within an image in the document. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. @@ -179,9 +175,26 @@ public Mono translate(String targetLanguage, DocumentTranslateConten */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public Mono translate(String targetLanguage, DocumentTranslateContent documentTranslateContent) { + public Mono translate(String targetLanguage, DocumentTranslateContent documentTranslateContent, + String sourceLanguage, String category, String deploymentName, Boolean allowFallback, + Boolean translateTextWithinImage) { // Generated convenience method for translateWithResponse RequestOptions requestOptions = new RequestOptions(); + if (sourceLanguage != null) { + requestOptions.addQueryParam("sourceLanguage", sourceLanguage, false); + } + if (category != null) { + requestOptions.addQueryParam("category", category, false); + } + if (deploymentName != null) { + requestOptions.addQueryParam("deploymentName", deploymentName, false); + } + if (allowFallback != null) { + requestOptions.addQueryParam("allowFallback", String.valueOf(allowFallback), false); + } + if (translateTextWithinImage != null) { + requestOptions.addQueryParam("translateTextWithinImage", String.valueOf(translateTextWithinImage), false); + } return translateWithResponse(targetLanguage, new MultipartFormDataHelper(requestOptions) .serializeFileField("document", documentTranslateContent.getDocument().getContent(), diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java index 38dfb0b312ea..56c26f3123b6 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java @@ -54,9 +54,13 @@ public final class SingleDocumentTranslationClient { * This parameter is used to get translations * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator * project details to this parameter to use your deployed customized system. Default value is: general. + * deploymentNameStringNoDeployment name of the custom translation model for the + * translation request. * allowFallbackBooleanNoSpecifies that the service is allowed to fall back to a * general system when a custom system doesn't exist. * Possible values are: true (default) or false. + * translateTextWithinImageBooleanNoOptional boolean parameter to translate text + * within an image in the document * * You can add these to a request with {@link RequestOptions#addQueryParam} *

Response Body Schema

@@ -96,16 +100,6 @@ Response translateWithResponse(String targetLanguage, BinaryData doc * The target language must be one of the supported languages included in the translation scope. * For example if you want to translate the document in German language, then use targetLanguage=de. * @param documentTranslateContent Document Translate Request Content. - * @param sourceLanguage Specifies source language of the input document. - * If this parameter isn't specified, automatic language detection is applied to determine the source language. - * For example if the source document is written in English, then use sourceLanguage=en. - * @param category A string specifying the category (domain) of the translation. This parameter is used to get - * translations - * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator - * project details to this parameter to use your deployed customized system. Default value is: general. - * @param allowFallback Specifies that the service is allowed to fall back to a general system when a custom system - * doesn't exist. - * Possible values are: true (default) or false. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. @@ -116,19 +110,9 @@ Response translateWithResponse(String targetLanguage, BinaryData doc */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public BinaryData translate(String targetLanguage, DocumentTranslateContent documentTranslateContent, - String sourceLanguage, String category, Boolean allowFallback) { + public BinaryData translate(String targetLanguage, DocumentTranslateContent documentTranslateContent) { // Generated convenience method for translateWithResponse RequestOptions requestOptions = new RequestOptions(); - if (sourceLanguage != null) { - requestOptions.addQueryParam("sourceLanguage", sourceLanguage, false); - } - if (category != null) { - requestOptions.addQueryParam("category", category, false); - } - if (allowFallback != null) { - requestOptions.addQueryParam("allowFallback", String.valueOf(allowFallback), false); - } return translateWithResponse(targetLanguage, new MultipartFormDataHelper(requestOptions) .serializeFileField("document", documentTranslateContent.getDocument().getContent(), @@ -167,6 +151,18 @@ public BinaryData translate(String targetLanguage, DocumentTranslateContent docu * The target language must be one of the supported languages included in the translation scope. * For example if you want to translate the document in German language, then use targetLanguage=de. * @param documentTranslateContent Document Translate Request Content. + * @param sourceLanguage Specifies source language of the input document. + * If this parameter isn't specified, automatic language detection is applied to determine the source language. + * For example if the source document is written in English, then use sourceLanguage=en. + * @param category A string specifying the category (domain) of the translation. This parameter is used to get + * translations + * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator + * project details to this parameter to use your deployed customized system. Default value is: general. + * @param deploymentName Deployment name of the custom translation model for the translation request. + * @param allowFallback Specifies that the service is allowed to fall back to a general system when a custom system + * doesn't exist. + * Possible values are: true (default) or false. + * @param translateTextWithinImage Optional boolean parameter to translate text within an image in the document. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. @@ -177,9 +173,26 @@ public BinaryData translate(String targetLanguage, DocumentTranslateContent docu */ @Generated @ServiceMethod(returns = ReturnType.SINGLE) - public BinaryData translate(String targetLanguage, DocumentTranslateContent documentTranslateContent) { + public BinaryData translate(String targetLanguage, DocumentTranslateContent documentTranslateContent, + String sourceLanguage, String category, String deploymentName, Boolean allowFallback, + Boolean translateTextWithinImage) { // Generated convenience method for translateWithResponse RequestOptions requestOptions = new RequestOptions(); + if (sourceLanguage != null) { + requestOptions.addQueryParam("sourceLanguage", sourceLanguage, false); + } + if (category != null) { + requestOptions.addQueryParam("category", category, false); + } + if (deploymentName != null) { + requestOptions.addQueryParam("deploymentName", deploymentName, false); + } + if (allowFallback != null) { + requestOptions.addQueryParam("allowFallback", String.valueOf(allowFallback), false); + } + if (translateTextWithinImage != null) { + requestOptions.addQueryParam("translateTextWithinImage", String.valueOf(translateTextWithinImage), false); + } return translateWithResponse(targetLanguage, new MultipartFormDataHelper(requestOptions) .serializeFileField("document", documentTranslateContent.getDocument().getContent(), diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java index cefc7bff3134..fe7db2d9ab96 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java @@ -179,8 +179,7 @@ public interface DocumentTranslationClientService { @UnexpectedResponseExceptionType(HttpResponseException.class) Mono> translation(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, - @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, - RequestOptions requestOptions, Context context); + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); @Post("/document/batches") @ExpectedResponses({ 202 }) @@ -190,8 +189,7 @@ Mono> translation(@HostParam("endpoint") String endpoint, @UnexpectedResponseExceptionType(HttpResponseException.class) Response translationSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, - @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, - RequestOptions requestOptions, Context context); + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); @Get("/document/batches") @ExpectedResponses({ 200 }) @@ -398,6 +396,7 @@ Response listDocumentStatusesNextSync( * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -413,6 +412,9 @@ Response listDocumentStatusesNextSync( * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -428,9 +430,8 @@ Response listDocumentStatusesNextSync( @ServiceMethod(returns = ReturnType.SINGLE) private Mono> translationWithResponseAsync(BinaryData body, RequestOptions requestOptions) { final String contentType = "application/json"; - final String accept = "application/json"; return FluxUtil.withContext(context -> service.translation(this.getEndpoint(), - this.getServiceVersion().getVersion(), contentType, accept, body, requestOptions, context)); + this.getServiceVersion().getVersion(), contentType, body, requestOptions, context)); } /** @@ -475,6 +476,7 @@ private Mono> translationWithResponseAsync(BinaryData body, Reque * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -490,6 +492,9 @@ private Mono> translationWithResponseAsync(BinaryData body, Reque * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -505,9 +510,8 @@ private Mono> translationWithResponseAsync(BinaryData body, Reque @ServiceMethod(returns = ReturnType.SINGLE) private Response translationWithResponse(BinaryData body, RequestOptions requestOptions) { final String contentType = "application/json"; - final String accept = "application/json"; - return service.translationSync(this.getEndpoint(), this.getServiceVersion().getVersion(), contentType, accept, - body, requestOptions, Context.NONE); + return service.translationSync(this.getEndpoint(), this.getServiceVersion().getVersion(), contentType, body, + requestOptions, Context.NONE); } /** @@ -552,6 +556,7 @@ private Response translationWithResponse(BinaryData body, RequestOptions r * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -567,6 +572,9 @@ private Response translationWithResponse(BinaryData body, RequestOptions r * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -635,6 +643,7 @@ public PollerFlux beginTransla * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -650,6 +659,9 @@ public PollerFlux beginTransla * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -718,6 +730,7 @@ public SyncPoller beginTransla * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -733,6 +746,9 @@ public SyncPoller beginTransla * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -799,6 +815,7 @@ public PollerFlux beginTranslationAsync(BinaryData body, * (Required){ * targetUrl: String (Required) * category: String (Optional) + * deploymentName: String (Optional) * language: String (Required) * glossaries (Optional): [ * (Optional){ @@ -814,6 +831,9 @@ public PollerFlux beginTranslationAsync(BinaryData body, * storageType: String(Folder/File) (Optional) * } * ] + * options (Optional): { + * translateTextWithinImage: Boolean (Optional) + * } * } * } * @@ -973,6 +993,9 @@ public SyncPoller beginTranslation(BinaryData body, Requ * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1131,6 +1154,9 @@ private Mono> listTranslationStatusesSinglePageAsync(R * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1307,6 +1333,9 @@ public PagedFlux listTranslationStatusesAsync(RequestOptions request * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1463,6 +1492,9 @@ private PagedResponse listTranslationStatusesSinglePage(RequestOptio * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1534,6 +1566,11 @@ public PagedIterable listTranslationStatuses(RequestOptions requestO * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -1585,6 +1622,11 @@ public Mono> getDocumentStatusWithResponseAsync(String tran * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -1641,6 +1683,9 @@ public Response getDocumentStatusWithResponse(String translationId, * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1697,6 +1742,9 @@ public Mono> getTranslationStatusWithResponseAsync(String t * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1756,6 +1804,9 @@ public Response getTranslationStatusWithResponse(String translationI * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1816,6 +1867,9 @@ public Mono> cancelTranslationWithResponseAsync(String tran * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -1962,6 +2016,11 @@ public Response cancelTranslationWithResponse(String translationId, * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -2111,6 +2170,11 @@ private Mono> listDocumentStatusesSinglePageAsync(Stri * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -2278,6 +2342,11 @@ public PagedFlux listDocumentStatusesAsync(String translationId, Req * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -2426,6 +2495,11 @@ private PagedResponse listDocumentStatusesSinglePage(String translat * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -2607,6 +2681,9 @@ public Response getSupportedFormatsWithResponse(RequestOptions reque * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -2664,6 +2741,9 @@ private Mono> listTranslationStatusesNextSinglePageAsy * notYetStarted: int (Required) * cancelled: int (Required) * totalCharacterCharged: long (Required) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * totalImageCharged: Long (Optional) * } * } * } @@ -2716,6 +2796,11 @@ private PagedResponse listTranslationStatusesNextSinglePage(String n * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * @@ -2767,6 +2852,11 @@ private Mono> listDocumentStatusesNextSinglePageAsync( * progress: double (Required) * id: String (Required) * characterCharged: Integer (Optional) + * totalImageScansSucceeded: Integer (Optional) + * totalImageScansFailed: Integer (Optional) + * imageCharged: Integer (Optional) + * imageCharacterDetected: Integer (Optional) + * deploymentName: String (Optional) * } * } * diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java index a18efdda76ef..91da5cb8facb 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java @@ -194,9 +194,13 @@ Response translateSync(@HostParam("endpoint") String endpoint, * This parameter is used to get translations * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator * project details to this parameter to use your deployed customized system. Default value is: general. + * deploymentNameStringNoDeployment name of the custom translation model for the + * translation request. * allowFallbackBooleanNoSpecifies that the service is allowed to fall back to a * general system when a custom system doesn't exist. * Possible values are: true (default) or false. + * translateTextWithinImageBooleanNoOptional boolean parameter to translate text + * within an image in the document * * You can add these to a request with {@link RequestOptions#addQueryParam} *

Response Body Schema

@@ -243,9 +247,13 @@ public Mono> translateWithResponseAsync(String targetLangua * This parameter is used to get translations * from a customized system built with Custom Translator. Add the Category ID from your Custom Translator * project details to this parameter to use your deployed customized system. Default value is: general. + * deploymentNameStringNoDeployment name of the custom translation model for the + * translation request. * allowFallbackBooleanNoSpecifies that the service is allowed to fall back to a * general system when a custom system doesn't exist. * Possible values are: true (default) or false. + * translateTextWithinImageBooleanNoOptional boolean parameter to translate text + * within an image in the document * * You can add these to a request with {@link RequestOptions#addQueryParam} *

Response Body Schema

diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/BatchOptions.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/BatchOptions.java new file mode 100644 index 000000000000..23d1be55a29d --- /dev/null +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/BatchOptions.java @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.translation.document.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Translation batch request options. + */ +@Fluent +public final class BatchOptions implements JsonSerializable { + + /* + * Translation text within an image option + */ + @Generated + private Boolean translateTextWithinImage; + + /** + * Creates an instance of BatchOptions class. + */ + @Generated + public BatchOptions() { + } + + /** + * Get the translateTextWithinImage property: Translation text within an image option. + * + * @return the translateTextWithinImage value. + */ + @Generated + public Boolean isTranslateTextWithinImage() { + return this.translateTextWithinImage; + } + + /** + * Set the translateTextWithinImage property: Translation text within an image option. + * + * @param translateTextWithinImage the translateTextWithinImage value to set. + * @return the BatchOptions object itself. + */ + @Generated + public BatchOptions setTranslateTextWithinImage(Boolean translateTextWithinImage) { + this.translateTextWithinImage = translateTextWithinImage; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeBooleanField("translateTextWithinImage", this.translateTextWithinImage); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of BatchOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of BatchOptions if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the BatchOptions. + */ + @Generated + public static BatchOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + BatchOptions deserializedBatchOptions = new BatchOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("translateTextWithinImage".equals(fieldName)) { + deserializedBatchOptions.translateTextWithinImage = reader.getNullable(JsonReader::getBoolean); + } else { + reader.skipChildren(); + } + } + return deserializedBatchOptions; + }); + } +} diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java index 08bdf8378158..6dd1248cf68a 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java @@ -240,6 +240,11 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("path", this.path); jsonWriter.writeJsonField("error", this.error); jsonWriter.writeNumberField("characterCharged", this.characterCharged); + jsonWriter.writeNumberField("totalImageScansSucceeded", this.totalImageScansSucceeded); + jsonWriter.writeNumberField("totalImageScansFailed", this.totalImageScansFailed); + jsonWriter.writeNumberField("imageCharged", this.imageCharged); + jsonWriter.writeNumberField("imageCharacterDetected", this.imageCharacterDetected); + jsonWriter.writeStringField("deploymentName", this.deploymentName); return jsonWriter.writeEndObject(); } @@ -265,6 +270,11 @@ public static DocumentStatusResult fromJson(JsonReader jsonReader) throws IOExce String path = null; TranslationError error = null; Integer characterCharged = null; + Integer totalImageScansSucceeded = null; + Integer totalImageScansFailed = null; + Integer imageCharged = null; + Integer imageCharacterDetected = null; + String deploymentName = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -290,6 +300,16 @@ public static DocumentStatusResult fromJson(JsonReader jsonReader) throws IOExce error = TranslationError.fromJson(reader); } else if ("characterCharged".equals(fieldName)) { characterCharged = reader.getNullable(JsonReader::getInt); + } else if ("totalImageScansSucceeded".equals(fieldName)) { + totalImageScansSucceeded = reader.getNullable(JsonReader::getInt); + } else if ("totalImageScansFailed".equals(fieldName)) { + totalImageScansFailed = reader.getNullable(JsonReader::getInt); + } else if ("imageCharged".equals(fieldName)) { + imageCharged = reader.getNullable(JsonReader::getInt); + } else if ("imageCharacterDetected".equals(fieldName)) { + imageCharacterDetected = reader.getNullable(JsonReader::getInt); + } else if ("deploymentName".equals(fieldName)) { + deploymentName = reader.getString(); } else { reader.skipChildren(); } @@ -299,7 +319,92 @@ public static DocumentStatusResult fromJson(JsonReader jsonReader) throws IOExce deserializedDocumentStatusResult.path = path; deserializedDocumentStatusResult.error = error; deserializedDocumentStatusResult.characterCharged = characterCharged; + deserializedDocumentStatusResult.totalImageScansSucceeded = totalImageScansSucceeded; + deserializedDocumentStatusResult.totalImageScansFailed = totalImageScansFailed; + deserializedDocumentStatusResult.imageCharged = imageCharged; + deserializedDocumentStatusResult.imageCharacterDetected = imageCharacterDetected; + deserializedDocumentStatusResult.deploymentName = deploymentName; return deserializedDocumentStatusResult; }); } + + /* + * Total image scans charged by the API + */ + @Generated + private Integer totalImageScansSucceeded; + + /* + * Total image scans failed + */ + @Generated + private Integer totalImageScansFailed; + + /* + * Images charged by the API + */ + @Generated + private Integer imageCharged; + + /* + * Characters detected within images + */ + @Generated + private Integer imageCharacterDetected; + + /* + * Deployment name of the custom translation model used for the translation + */ + @Generated + private String deploymentName; + + /** + * Get the totalImageScansSucceeded property: Total image scans charged by the API. + * + * @return the totalImageScansSucceeded value. + */ + @Generated + public Integer getTotalImageScansSucceeded() { + return this.totalImageScansSucceeded; + } + + /** + * Get the totalImageScansFailed property: Total image scans failed. + * + * @return the totalImageScansFailed value. + */ + @Generated + public Integer getTotalImageScansFailed() { + return this.totalImageScansFailed; + } + + /** + * Get the imageCharged property: Images charged by the API. + * + * @return the imageCharged value. + */ + @Generated + public Integer getImageCharged() { + return this.imageCharged; + } + + /** + * Get the imageCharacterDetected property: Characters detected within images. + * + * @return the imageCharacterDetected value. + */ + @Generated + public Integer getImageCharacterDetected() { + return this.imageCharacterDetected; + } + + /** + * Get the deploymentName property: Deployment name of the custom translation model used for the translation. + * + * @return the deploymentName value. + */ + @Generated + public String getDeploymentName() { + return this.deploymentName; + } } diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java index 928d197a9efe..fa55d09ad662 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java @@ -3,8 +3,8 @@ // Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.ai.translation.document.models; +import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -15,7 +15,7 @@ /** * Translation job submission batch request. */ -@Immutable +@Fluent public final class TranslationBatch implements JsonSerializable { /* @@ -52,6 +52,7 @@ public List getInputs() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeArrayField("inputs", this.inputs, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeJsonField("options", this.options); return jsonWriter.writeEndObject(); } @@ -68,16 +69,49 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { public static TranslationBatch fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { List inputs = null; + BatchOptions options = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); if ("inputs".equals(fieldName)) { inputs = reader.readArray(reader1 -> DocumentTranslationInput.fromJson(reader1)); + } else if ("options".equals(fieldName)) { + options = BatchOptions.fromJson(reader); } else { reader.skipChildren(); } } - return new TranslationBatch(inputs); + TranslationBatch deserializedTranslationBatch = new TranslationBatch(inputs); + deserializedTranslationBatch.options = options; + return deserializedTranslationBatch; }); } + + /* + * The batch operation options + */ + @Generated + private BatchOptions options; + + /** + * Get the options property: The batch operation options. + * + * @return the options value. + */ + @Generated + public BatchOptions getOptions() { + return this.options; + } + + /** + * Set the options property: The batch operation options. + * + * @param options the options value to set. + * @return the TranslationBatch object itself. + */ + @Generated + public TranslationBatch setOptions(BatchOptions options) { + this.options = options; + return this; + } } diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java index 2c2aa6db1b74..999bf92c247f 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java @@ -166,6 +166,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeIntField("notYetStarted", this.notYetStartedCount); jsonWriter.writeIntField("cancelled", this.cancelledCount); jsonWriter.writeLongField("totalCharacterCharged", this.totalCharactersChargedCount); + jsonWriter.writeNumberField("totalImageScansSucceeded", this.totalImageScansSucceeded); + jsonWriter.writeNumberField("totalImageScansFailed", this.totalImageScansFailed); + jsonWriter.writeNumberField("totalImageCharged", this.totalImagesChargedCount); return jsonWriter.writeEndObject(); } @@ -188,6 +191,9 @@ public static TranslationStatusSummary fromJson(JsonReader jsonReader) throws IO int notYetStartedCount = 0; int cancelledCount = 0; long totalCharactersChargedCount = 0L; + Integer totalImageScansSucceeded = null; + Integer totalImageScansFailed = null; + Long totalImagesChargedCount = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -205,12 +211,71 @@ public static TranslationStatusSummary fromJson(JsonReader jsonReader) throws IO cancelledCount = reader.getInt(); } else if ("totalCharacterCharged".equals(fieldName)) { totalCharactersChargedCount = reader.getLong(); + } else if ("totalImageScansSucceeded".equals(fieldName)) { + totalImageScansSucceeded = reader.getNullable(JsonReader::getInt); + } else if ("totalImageScansFailed".equals(fieldName)) { + totalImageScansFailed = reader.getNullable(JsonReader::getInt); + } else if ("totalImageCharged".equals(fieldName)) { + totalImagesChargedCount = reader.getNullable(JsonReader::getLong); } else { reader.skipChildren(); } } - return new TranslationStatusSummary(totalCount, failedCount, successCount, inProgressCount, - notYetStartedCount, cancelledCount, totalCharactersChargedCount); + TranslationStatusSummary deserializedTranslationStatusSummary + = new TranslationStatusSummary(totalCount, failedCount, successCount, inProgressCount, + notYetStartedCount, cancelledCount, totalCharactersChargedCount); + deserializedTranslationStatusSummary.totalImageScansSucceeded = totalImageScansSucceeded; + deserializedTranslationStatusSummary.totalImageScansFailed = totalImageScansFailed; + deserializedTranslationStatusSummary.totalImagesChargedCount = totalImagesChargedCount; + return deserializedTranslationStatusSummary; }); } + + /* + * Total image scans charged by the API + */ + @Generated + private Integer totalImageScansSucceeded; + + /* + * Total image scans failed + */ + @Generated + private Integer totalImageScansFailed; + + /* + * Total images charged by the API + */ + @Generated + private Long totalImagesChargedCount; + + /** + * Get the totalImageScansSucceeded property: Total image scans charged by the API. + * + * @return the totalImageScansSucceeded value. + */ + @Generated + public Integer getTotalImageScansSucceeded() { + return this.totalImageScansSucceeded; + } + + /** + * Get the totalImageScansFailed property: Total image scans failed. + * + * @return the totalImageScansFailed value. + */ + @Generated + public Integer getTotalImageScansFailed() { + return this.totalImageScansFailed; + } + + /** + * Get the totalImagesChargedCount property: Total images charged by the API. + * + * @return the totalImagesChargedCount value. + */ + @Generated + public Long getTotalImagesChargedCount() { + return this.totalImagesChargedCount; + } } diff --git a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java index 8ae22be058e3..670ecf485315 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java +++ b/sdk/translation/azure-ai-translation-document/src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java @@ -156,6 +156,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("targetUrl", this.targetUrl); jsonWriter.writeStringField("language", this.language); jsonWriter.writeStringField("category", this.category); + jsonWriter.writeStringField("deploymentName", this.deploymentName); jsonWriter.writeArrayField("glossaries", this.glossaries, (writer, element) -> writer.writeJson(element)); jsonWriter.writeStringField("storageSource", this.storageSource == null ? null : this.storageSource.toString()); return jsonWriter.writeEndObject(); @@ -176,6 +177,7 @@ public static TranslationTarget fromJson(JsonReader jsonReader) throws IOExcepti String targetUrl = null; String language = null; String category = null; + String deploymentName = null; List glossaries = null; TranslationStorageSource storageSource = null; while (reader.nextToken() != JsonToken.END_OBJECT) { @@ -187,6 +189,8 @@ public static TranslationTarget fromJson(JsonReader jsonReader) throws IOExcepti language = reader.getString(); } else if ("category".equals(fieldName)) { category = reader.getString(); + } else if ("deploymentName".equals(fieldName)) { + deploymentName = reader.getString(); } else if ("glossaries".equals(fieldName)) { glossaries = reader.readArray(reader1 -> TranslationGlossary.fromJson(reader1)); } else if ("storageSource".equals(fieldName)) { @@ -197,9 +201,38 @@ public static TranslationTarget fromJson(JsonReader jsonReader) throws IOExcepti } TranslationTarget deserializedTranslationTarget = new TranslationTarget(targetUrl, language); deserializedTranslationTarget.category = category; + deserializedTranslationTarget.deploymentName = deploymentName; deserializedTranslationTarget.glossaries = glossaries; deserializedTranslationTarget.storageSource = storageSource; return deserializedTranslationTarget; }); } + + /* + * Deployment name of the custom translation model for the translation request. + */ + @Generated + private String deploymentName; + + /** + * Get the deploymentName property: Deployment name of the custom translation model for the translation request. + * + * @return the deploymentName value. + */ + @Generated + public String getDeploymentName() { + return this.deploymentName; + } + + /** + * Set the deploymentName property: Deployment name of the custom translation model for the translation request. + * + * @param deploymentName the deploymentName value to set. + * @return the TranslationTarget object itself. + */ + @Generated + public TranslationTarget setDeploymentName(String deploymentName) { + this.deploymentName = deploymentName; + return this; + } } diff --git a/sdk/translation/azure-ai-translation-document/src/main/resources/META-INF/azure-ai-translation-document_metadata.json b/sdk/translation/azure-ai-translation-document/src/main/resources/META-INF/azure-ai-translation-document_metadata.json index efe1fb3f6ff5..19f9064bf8ad 100644 --- a/sdk/translation/azure-ai-translation-document/src/main/resources/META-INF/azure-ai-translation-document_metadata.json +++ b/sdk/translation/azure-ai-translation-document/src/main/resources/META-INF/azure-ai-translation-document_metadata.json @@ -1 +1 @@ -{"flavor":"azure","apiVersions":{"DocumentTranslation":"2024-05-01"},"crossLanguageDefinitions":{"com.azure.ai.translation.document.DocumentTranslationAsyncClient":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.DocumentTranslationAsyncClient.beginTranslation":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.beginTranslationWithModel":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.cancelTranslation":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.cancelTranslationWithResponse":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getDocumentStatus":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getDocumentStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getTranslationStatus":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getTranslationStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClient":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.DocumentTranslationClient.beginTranslation":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationClient.beginTranslationWithModel":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationClient.cancelTranslation":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationClient.cancelTranslationWithResponse":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationClient.getDocumentStatus":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationClient.getDocumentStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationClient.getTranslationStatus":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClient.getTranslationStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClientBuilder":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient.translate":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient.translateWithResponse":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClient":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationClient.translate":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClient.translateWithResponse":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClientBuilder":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.implementation.models.InnerTranslationError":"DocumentTranslation.InnerTranslationError","com.azure.ai.translation.document.implementation.models.SupportedFileFormats":"DocumentTranslation.SupportedFileFormats","com.azure.ai.translation.document.implementation.models.TranslationError":"DocumentTranslation.TranslationError","com.azure.ai.translation.document.implementation.models.TranslationErrorCode":"DocumentTranslation.TranslationErrorCode","com.azure.ai.translation.document.models.DocumentFileDetails":null,"com.azure.ai.translation.document.models.DocumentFilter":"DocumentTranslation.DocumentFilter","com.azure.ai.translation.document.models.DocumentStatusResult":"DocumentTranslation.DocumentStatus","com.azure.ai.translation.document.models.DocumentTranslateContent":"DocumentTranslation.DocumentTranslateContent","com.azure.ai.translation.document.models.DocumentTranslationInput":"DocumentTranslation.BatchRequest","com.azure.ai.translation.document.models.FileFormat":"DocumentTranslation.FileFormat","com.azure.ai.translation.document.models.FileFormatType":"DocumentTranslation.FileFormatType","com.azure.ai.translation.document.models.GlossaryFileDetails":null,"com.azure.ai.translation.document.models.StorageInputType":"DocumentTranslation.StorageInputType","com.azure.ai.translation.document.models.TranslationBatch":"DocumentTranslation.StartTranslationDetails","com.azure.ai.translation.document.models.TranslationGlossary":"DocumentTranslation.Glossary","com.azure.ai.translation.document.models.TranslationSource":"DocumentTranslation.SourceInput","com.azure.ai.translation.document.models.TranslationStatus":"DocumentTranslation.Status","com.azure.ai.translation.document.models.TranslationStatusResult":"DocumentTranslation.TranslationStatus","com.azure.ai.translation.document.models.TranslationStatusSummary":"DocumentTranslation.StatusSummary","com.azure.ai.translation.document.models.TranslationStorageSource":"DocumentTranslation.StorageSource","com.azure.ai.translation.document.models.TranslationTarget":"DocumentTranslation.TargetInput"},"generatedFiles":["src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationClientBuilder.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClientBuilder.java","src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java","src/main/java/com/azure/ai/translation/document/implementation/MultipartFormDataHelper.java","src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java","src/main/java/com/azure/ai/translation/document/implementation/models/InnerTranslationError.java","src/main/java/com/azure/ai/translation/document/implementation/models/SupportedFileFormats.java","src/main/java/com/azure/ai/translation/document/implementation/models/TranslationError.java","src/main/java/com/azure/ai/translation/document/implementation/models/TranslationErrorCode.java","src/main/java/com/azure/ai/translation/document/implementation/models/package-info.java","src/main/java/com/azure/ai/translation/document/implementation/package-info.java","src/main/java/com/azure/ai/translation/document/models/DocumentFileDetails.java","src/main/java/com/azure/ai/translation/document/models/DocumentFilter.java","src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java","src/main/java/com/azure/ai/translation/document/models/DocumentTranslateContent.java","src/main/java/com/azure/ai/translation/document/models/DocumentTranslationInput.java","src/main/java/com/azure/ai/translation/document/models/FileFormat.java","src/main/java/com/azure/ai/translation/document/models/FileFormatType.java","src/main/java/com/azure/ai/translation/document/models/GlossaryFileDetails.java","src/main/java/com/azure/ai/translation/document/models/StorageInputType.java","src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java","src/main/java/com/azure/ai/translation/document/models/TranslationGlossary.java","src/main/java/com/azure/ai/translation/document/models/TranslationSource.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatus.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatusResult.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java","src/main/java/com/azure/ai/translation/document/models/TranslationStorageSource.java","src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java","src/main/java/com/azure/ai/translation/document/models/package-info.java","src/main/java/com/azure/ai/translation/document/package-info.java","src/main/java/module-info.java"]} \ No newline at end of file +{"flavor":"azure","apiVersions":{"DocumentTranslation":"2026-03-01"},"crossLanguagePackageId":"DocumentTranslation","crossLanguageVersion":"723f2ac3b34d","crossLanguageDefinitions":{"com.azure.ai.translation.document.DocumentTranslationAsyncClient":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.DocumentTranslationAsyncClient.beginTranslation":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.beginTranslationWithModel":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.cancelTranslation":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.cancelTranslationWithResponse":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getDocumentStatus":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getDocumentStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getTranslationStatus":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationAsyncClient.getTranslationStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClient":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.DocumentTranslationClient.beginTranslation":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationClient.beginTranslationWithModel":"ClientCustomizations.DocumentTranslationClient.startTranslation","com.azure.ai.translation.document.DocumentTranslationClient.cancelTranslation":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationClient.cancelTranslationWithResponse":"ClientCustomizations.DocumentTranslationClient.cancelTranslation","com.azure.ai.translation.document.DocumentTranslationClient.getDocumentStatus":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationClient.getDocumentStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getDocumentStatus","com.azure.ai.translation.document.DocumentTranslationClient.getTranslationStatus":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClient.getTranslationStatusWithResponse":"ClientCustomizations.DocumentTranslationClient.getTranslationStatus","com.azure.ai.translation.document.DocumentTranslationClientBuilder":"ClientCustomizations.DocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient.translate":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationAsyncClient.translateWithResponse":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClient":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.SingleDocumentTranslationClient.translate":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClient.translateWithResponse":"ClientCustomizations.SingleDocumentTranslationClient.documentTranslate","com.azure.ai.translation.document.SingleDocumentTranslationClientBuilder":"ClientCustomizations.SingleDocumentTranslationClient","com.azure.ai.translation.document.implementation.models.InnerTranslationError":"DocumentTranslation.InnerTranslationError","com.azure.ai.translation.document.implementation.models.SupportedFileFormats":"DocumentTranslation.SupportedFileFormats","com.azure.ai.translation.document.implementation.models.TranslationError":"DocumentTranslation.TranslationError","com.azure.ai.translation.document.implementation.models.TranslationErrorCode":"DocumentTranslation.TranslationErrorCode","com.azure.ai.translation.document.models.BatchOptions":"DocumentTranslation.BatchOptions","com.azure.ai.translation.document.models.DocumentFileDetails":null,"com.azure.ai.translation.document.models.DocumentFilter":"DocumentTranslation.DocumentFilter","com.azure.ai.translation.document.models.DocumentStatusResult":"DocumentTranslation.DocumentStatus","com.azure.ai.translation.document.models.DocumentTranslateContent":"DocumentTranslation.DocumentTranslateContent","com.azure.ai.translation.document.models.DocumentTranslationInput":"DocumentTranslation.BatchRequest","com.azure.ai.translation.document.models.FileFormat":"DocumentTranslation.FileFormat","com.azure.ai.translation.document.models.FileFormatType":"DocumentTranslation.FileFormatType","com.azure.ai.translation.document.models.GlossaryFileDetails":null,"com.azure.ai.translation.document.models.StorageInputType":"DocumentTranslation.StorageInputType","com.azure.ai.translation.document.models.TranslationBatch":"DocumentTranslation.StartTranslationDetails","com.azure.ai.translation.document.models.TranslationGlossary":"DocumentTranslation.Glossary","com.azure.ai.translation.document.models.TranslationSource":"DocumentTranslation.SourceInput","com.azure.ai.translation.document.models.TranslationStatus":"DocumentTranslation.Status","com.azure.ai.translation.document.models.TranslationStatusResult":"DocumentTranslation.TranslationStatus","com.azure.ai.translation.document.models.TranslationStatusSummary":"DocumentTranslation.StatusSummary","com.azure.ai.translation.document.models.TranslationStorageSource":"DocumentTranslation.StorageSource","com.azure.ai.translation.document.models.TranslationTarget":"DocumentTranslation.TargetInput"},"generatedFiles":["src/main/java/com/azure/ai/translation/document/DocumentTranslationAsyncClient.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationClient.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationClientBuilder.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java","src/main/java/com/azure/ai/translation/document/DocumentTranslationServiceVersion.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationAsyncClient.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClient.java","src/main/java/com/azure/ai/translation/document/SingleDocumentTranslationClientBuilder.java","src/main/java/com/azure/ai/translation/document/implementation/DocumentTranslationClientImpl.java","src/main/java/com/azure/ai/translation/document/implementation/MultipartFormDataHelper.java","src/main/java/com/azure/ai/translation/document/implementation/SingleDocumentTranslationClientImpl.java","src/main/java/com/azure/ai/translation/document/implementation/models/InnerTranslationError.java","src/main/java/com/azure/ai/translation/document/implementation/models/SupportedFileFormats.java","src/main/java/com/azure/ai/translation/document/implementation/models/TranslationError.java","src/main/java/com/azure/ai/translation/document/implementation/models/TranslationErrorCode.java","src/main/java/com/azure/ai/translation/document/implementation/models/package-info.java","src/main/java/com/azure/ai/translation/document/implementation/package-info.java","src/main/java/com/azure/ai/translation/document/models/BatchOptions.java","src/main/java/com/azure/ai/translation/document/models/DocumentFileDetails.java","src/main/java/com/azure/ai/translation/document/models/DocumentFilter.java","src/main/java/com/azure/ai/translation/document/models/DocumentStatusResult.java","src/main/java/com/azure/ai/translation/document/models/DocumentTranslateContent.java","src/main/java/com/azure/ai/translation/document/models/DocumentTranslationInput.java","src/main/java/com/azure/ai/translation/document/models/FileFormat.java","src/main/java/com/azure/ai/translation/document/models/FileFormatType.java","src/main/java/com/azure/ai/translation/document/models/GlossaryFileDetails.java","src/main/java/com/azure/ai/translation/document/models/StorageInputType.java","src/main/java/com/azure/ai/translation/document/models/TranslationBatch.java","src/main/java/com/azure/ai/translation/document/models/TranslationGlossary.java","src/main/java/com/azure/ai/translation/document/models/TranslationSource.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatus.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatusResult.java","src/main/java/com/azure/ai/translation/document/models/TranslationStatusSummary.java","src/main/java/com/azure/ai/translation/document/models/TranslationStorageSource.java","src/main/java/com/azure/ai/translation/document/models/TranslationTarget.java","src/main/java/com/azure/ai/translation/document/models/package-info.java","src/main/java/com/azure/ai/translation/document/package-info.java","src/main/java/module-info.java"]} \ No newline at end of file diff --git a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithCustomModel.java b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithCustomModel.java new file mode 100644 index 000000000000..3c932b20fff4 --- /dev/null +++ b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithCustomModel.java @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.translation.document; + +import com.azure.ai.translation.document.models.DocumentFileDetails; +import com.azure.ai.translation.document.models.DocumentStatusResult; +import com.azure.ai.translation.document.models.DocumentTranslateContent; +import com.azure.ai.translation.document.models.DocumentTranslationInput; +import com.azure.ai.translation.document.models.TranslationSource; +import com.azure.ai.translation.document.models.TranslationStatusResult; +import com.azure.ai.translation.document.models.TranslationStorageSource; +import com.azure.ai.translation.document.models.TranslationTarget; +import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.BinaryData; +import com.azure.core.util.polling.SyncPoller; + +import java.util.ArrayList; +import java.util.List; + +/** + * Sample demonstrating how to translate documents with a custom translation model by providing its + * deployment name, for both batch and single document translation. + */ +public class TranslateWithCustomModel { + public static void main(final String[] args) { + String endpoint = System.getenv("DOCUMENT_TRANSLATION_ENDPOINT"); + String apiKey = System.getenv("DOCUMENT_TRANSLATION_API_KEY"); + AzureKeyCredential credential = new AzureKeyCredential(apiKey); + + batchTranslationWithCustomModel(endpoint, credential); + singleDocumentTranslationWithCustomModel(endpoint, credential); + } + + private static void batchTranslationWithCustomModel(String endpoint, AzureKeyCredential credential) { + DocumentTranslationClient documentTranslationClient = new DocumentTranslationClientBuilder() + .endpoint(endpoint) + .credential(credential) + .buildClient(); + + // BEGIN:startDocumentTranslationWithCustomModel + String sourceUrl = "https://myblob.blob.core.windows.net/sourceContainer"; + TranslationSource translationSource = new TranslationSource(sourceUrl); + translationSource.setLanguage("en"); + translationSource.setStorageSource(TranslationStorageSource.AZURE_BLOB); + + String targetUrl = "https://myblob.blob.core.windows.net/destinationContainer"; + TranslationTarget translationTarget = new TranslationTarget(targetUrl, "es"); + // Set the deployment name of your custom translation model on the target. + translationTarget.setDeploymentName(""); + translationTarget.setStorageSource(TranslationStorageSource.AZURE_BLOB); + + List translationTargets = new ArrayList<>(); + translationTargets.add(translationTarget); + + DocumentTranslationInput batchRequest = new DocumentTranslationInput(translationSource, translationTargets); + + SyncPoller poller = documentTranslationClient + .beginTranslation(TestHelper.getStartTranslationDetails(batchRequest)); + TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); + + for (DocumentStatusResult document : documentTranslationClient.listDocumentStatuses(translationStatus.getId())) { + System.out.println("Document Id: " + document.getId()); + System.out.println("Document Status: " + document.getStatus()); + // The status reports the deployment name of the custom model that was used. + System.out.println("Deployment name used: " + document.getDeploymentName()); + } + // END:startDocumentTranslationWithCustomModel + } + + private static void singleDocumentTranslationWithCustomModel(String endpoint, AzureKeyCredential credential) { + SingleDocumentTranslationClient singleDocumentTranslationClient = new SingleDocumentTranslationClientBuilder() + .endpoint(endpoint) + .credential(credential) + .buildClient(); + + // BEGIN:singleDocumentTranslationWithCustomModel + DocumentFileDetails document = new DocumentFileDetails(BinaryData.fromString("This is a test document.")) + .setFilename("test-input.txt") + .setContentType("text/html"); + DocumentTranslateContent documentTranslateContent = new DocumentTranslateContent(document); + + String targetLanguage = "hi"; + String sourceLanguage = null; + String category = null; + // Provide the custom model deployment name for the translation. + String deploymentName = ""; + Boolean allowFallback = null; + Boolean translateTextWithinImage = null; + + BinaryData response = singleDocumentTranslationClient.translate(targetLanguage, documentTranslateContent, + sourceLanguage, category, deploymentName, allowFallback, translateTextWithinImage); + System.out.println("Translated Response: " + response); + // END:singleDocumentTranslationWithCustomModel + } +} diff --git a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithImageTranslation.java b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithImageTranslation.java new file mode 100644 index 000000000000..027dcdcf000f --- /dev/null +++ b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/TranslateWithImageTranslation.java @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.translation.document; + +import com.azure.ai.translation.document.models.DocumentStatusResult; +import com.azure.ai.translation.document.models.DocumentTranslationInput; +import com.azure.ai.translation.document.models.TranslationSource; +import com.azure.ai.translation.document.models.TranslationStatusResult; +import com.azure.ai.translation.document.models.TranslationStorageSource; +import com.azure.ai.translation.document.models.TranslationTarget; +import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.polling.SyncPoller; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Sample demonstrating how to start a batch translation that also translates text embedded within + * images in the documents, and how to read the image scan usage reported on each document's status. + */ +public class TranslateWithImageTranslation { + public static void main(final String[] args) { + String endpoint = System.getenv("DOCUMENT_TRANSLATION_ENDPOINT"); + String apiKey = System.getenv("DOCUMENT_TRANSLATION_API_KEY"); + AzureKeyCredential credential = new AzureKeyCredential(apiKey); + + DocumentTranslationClient documentTranslationClient = new DocumentTranslationClientBuilder() + .endpoint(endpoint) + .credential(credential) + .buildClient(); + + // BEGIN:startDocumentTranslationWithImageTranslation + String sourceUrl = "https://myblob.blob.core.windows.net/sourceContainer"; + TranslationSource translationSource = new TranslationSource(sourceUrl); + translationSource.setLanguage("en"); + translationSource.setStorageSource(TranslationStorageSource.AZURE_BLOB); + + String targetUrl = "https://myblob.blob.core.windows.net/destinationContainer"; + TranslationTarget translationTarget = new TranslationTarget(targetUrl, "es"); + translationTarget.setStorageSource(TranslationStorageSource.AZURE_BLOB); + + List translationTargets = new ArrayList<>(); + translationTargets.add(translationTarget); + + DocumentTranslationInput batchRequest = new DocumentTranslationInput(translationSource, translationTargets); + + // Enable translation of text embedded within images for the batch using the convenience overload. + SyncPoller poller + = documentTranslationClient.beginTranslation(Arrays.asList(batchRequest), true); + TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); + + for (DocumentStatusResult document : documentTranslationClient.listDocumentStatuses(translationStatus.getId())) { + System.out.println("Document Id: " + document.getId()); + System.out.println("Document Status: " + document.getStatus()); + // Image scan usage is reported when image translation is enabled. + System.out.println("Total image scans succeeded: " + document.getTotalImageScansSucceeded()); + System.out.println("Total image scans failed: " + document.getTotalImageScansFailed()); + System.out.println("Images charged: " + document.getImageCharged()); + System.out.println("Characters detected within images: " + document.getImageCharacterDetected()); + } + // END:startDocumentTranslationWithImageTranslation + } +} diff --git a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/SubmitADocumentTranslationRequestToTheDocumentTranslationService.java b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/SubmitADocumentTranslationRequestToTheDocumentTranslationService.java index 208a7c21c798..6daf294ac24d 100644 --- a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/SubmitADocumentTranslationRequestToTheDocumentTranslationService.java +++ b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/SubmitADocumentTranslationRequestToTheDocumentTranslationService.java @@ -6,6 +6,7 @@ import com.azure.ai.translation.document.DocumentTranslationClient; import com.azure.ai.translation.document.DocumentTranslationClientBuilder; +import com.azure.ai.translation.document.models.BatchOptions; import com.azure.ai.translation.document.models.DocumentFilter; import com.azure.ai.translation.document.models.DocumentTranslationInput; import com.azure.ai.translation.document.models.StorageInputType; @@ -34,15 +35,16 @@ public static void main(String[] args) { .setStorageSource(TranslationStorageSource.AZURE_BLOB), Arrays.asList( new TranslationTarget("https://myblob.blob.core.windows.net/destinationContainer1", "fr") - .setCategory("general") + .setDeploymentName("gpt-4o-mini") .setGlossaries(Arrays.asList(new TranslationGlossary( "https://myblob.blob.core.windows.net/myglossary/en_fr_glossary.xlf", "XLIFF") .setStorageSource(TranslationStorageSource.AZURE_BLOB))) .setStorageSource(TranslationStorageSource.AZURE_BLOB), new TranslationTarget("https://myblob.blob.core.windows.net/destinationContainer2", "es") - .setCategory("general") + .setDeploymentName("gpt-4o-mini") .setStorageSource(TranslationStorageSource.AZURE_BLOB))) - .setStorageType(StorageInputType.FOLDER)))); + .setStorageType(StorageInputType.FOLDER))) + .setOptions(new BatchOptions().setTranslateTextWithinImage(true))); // END:com.azure.ai.translation.document.generated.translation.submit-a-document-translation-request-to-the-document-translation-service } } diff --git a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/TranslateASingleDocument.java b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/TranslateASingleDocument.java index 5c10e73bb20d..8abaeba242f5 100644 --- a/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/TranslateASingleDocument.java +++ b/sdk/translation/azure-ai-translation-document/src/samples/java/com/azure/ai/translation/document/generated/TranslateASingleDocument.java @@ -17,7 +17,8 @@ public static void main(String[] args) { .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) .buildClient(); // BEGIN:com.azure.ai.translation.document.generated.translate.translate-a-single-document - BinaryData response = singleDocumentTranslationClient.translate("es", null, "en", null, null); + BinaryData response + = singleDocumentTranslationClient.translate("es", null, "en", null, "gpt-4o-mini", null, true); // END:com.azure.ai.translation.document.generated.translate.translate-a-single-document } } diff --git a/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationClientTestBase.java b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationClientTestBase.java index 49ebd4e8326a..c6cc48ebf7af 100644 --- a/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationClientTestBase.java +++ b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationClientTestBase.java @@ -30,6 +30,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -165,6 +168,23 @@ String createSourceContainer(List documents) { return blobContainerClient.getBlobContainerUrl(); } + String createSourceContainerFromFile(String fileName) { + String containerName = testResourceNamer.randomName("source", 10); + BlobContainerClient blobContainerClient = getBlobContainerClient(containerName); + if (!blobContainerClient.exists()) { + blobContainerClient.create(); + } + try { + Path filePath = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", fileName); + byte[] data = Files.readAllBytes(filePath); + BlobClient blobClient = blobContainerClient.getBlobClient(fileName); + blobClient.upload(new ByteArrayInputStream(data), true); + } catch (IOException e) { + throw new RuntimeException("Failed to upload test file: " + fileName, e); + } + return blobContainerClient.getBlobContainerUrl(); + } + String createTargetContainer(List documents) { String containerName = testResourceNamer.randomName("target", 10); BlobContainerClient blobContainerClient = createContainer(containerName, documents); diff --git a/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationModelTests.java b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationModelTests.java new file mode 100644 index 000000000000..063da3b8f87c --- /dev/null +++ b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationModelTests.java @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.translation.document; + +import com.azure.ai.translation.document.models.BatchOptions; +import com.azure.ai.translation.document.models.DocumentStatusResult; +import com.azure.ai.translation.document.models.DocumentTranslationInput; +import com.azure.ai.translation.document.models.TranslationBatch; +import com.azure.ai.translation.document.models.TranslationSource; +import com.azure.ai.translation.document.models.TranslationTarget; +import com.azure.json.JsonProviders; +import com.azure.json.JsonReader; +import com.azure.json.JsonWriter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Unit tests validating serialization of the image translation and custom deployment name features + * added in the 2026-03-01 service version. These do not require a live service. + */ +public class DocumentTranslationModelTests { + + @Test + public void translationTargetSerializesDeploymentName() throws IOException { + TranslationTarget target = new TranslationTarget("https://myblob.blob.core.windows.net/target", "fr") + .setDeploymentName("myDeployment"); + + String json = toJson(target); + + Assertions.assertTrue(json.contains("\"deploymentName\":\"myDeployment\""), + "Expected serialized TranslationTarget to contain the deploymentName property. Actual: " + json); + } + + @Test + public void translationBatchSerializesTranslateTextWithinImage() throws IOException { + TranslationSource source = new TranslationSource("https://myblob.blob.core.windows.net/source"); + TranslationTarget target = new TranslationTarget("https://myblob.blob.core.windows.net/target", "fr"); + DocumentTranslationInput input = new DocumentTranslationInput(source, new ArrayList<>(Arrays.asList(target))); + + TranslationBatch batch = new TranslationBatch(new ArrayList<>(Arrays.asList(input))) + .setOptions(new BatchOptions().setTranslateTextWithinImage(true)); + + String json = toJson(batch); + + Assertions.assertTrue(json.contains("\"translateTextWithinImage\":true"), + "Expected serialized TranslationBatch to contain translateTextWithinImage. Actual: " + json); + } + + @Test + public void documentStatusResultDeserializesDeploymentNameAndImageUsage() throws IOException { + String json = "{" + "\"path\":\"https://target/doc.txt\"," + "\"sourcePath\":\"https://source/doc.txt\"," + + "\"createdDateTimeUtc\":\"2026-03-01T00:00:00.0000000Z\"," + + "\"lastActionDateTimeUtc\":\"2026-03-01T00:05:00.0000000Z\"," + "\"status\":\"Succeeded\"," + + "\"to\":\"es\"," + "\"progress\":1.0," + "\"id\":\"doc-1\"," + "\"characterCharged\":100," + + "\"totalImageScansSucceeded\":6," + "\"totalImageScansFailed\":1," + "\"imageCharged\":3," + + "\"imageCharacterDetected\":1257," + "\"deploymentName\":\"myDeployment\"" + "}"; + + DocumentStatusResult result; + try (JsonReader reader = JsonProviders.createReader(json)) { + result = DocumentStatusResult.fromJson(reader); + } + + Assertions.assertEquals("myDeployment", result.getDeploymentName()); + Assertions.assertEquals(6, result.getTotalImageScansSucceeded()); + Assertions.assertEquals(1, result.getTotalImageScansFailed()); + Assertions.assertEquals(3, result.getImageCharged()); + Assertions.assertEquals(1257, result.getImageCharacterDetected()); + } + + private static String toJson(com.azure.json.JsonSerializable serializable) throws IOException { + try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); + JsonWriter writer = JsonProviders.createWriter(stream)) { + serializable.toJson(writer); + writer.flush(); + return stream.toString(StandardCharsets.UTF_8.name()); + } + } +} diff --git a/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationTests.java b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationTests.java index f80c3b305a58..11320827a3be 100644 --- a/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationTests.java +++ b/sdk/translation/azure-ai-translation-document/src/test/java/com/azure/ai/translation/document/DocumentTranslationTests.java @@ -11,7 +11,6 @@ import com.azure.ai.translation.document.models.TranslationTarget; import com.azure.ai.translation.document.models.TranslationStatusResult; import com.azure.core.models.ResponseError; -import com.azure.core.exception.ClientAuthenticationException; import com.azure.core.exception.ResourceNotFoundException; import com.azure.core.http.rest.PagedIterable; import com.azure.core.test.TestMode; @@ -37,21 +36,33 @@ public class DocumentTranslationTests extends DocumentTranslationClientTestBase @RecordWithoutRequestBody @Test - public void testClientCannotAuthenticateWithFakeApiKey() { - String testEndpoint = "https://t7d8641d8f25ec940-doctranslation.cognitiveservices.azure.com"; - String testApiKey = "fakeApiKey"; + public void testSingleSourceSingleTarget() { + DocumentTranslationClient documentTranslationClient = getDocumentTranslationClient(); + String sourceUrl = createSourceContainer(ONE_TEST_DOCUMENTS); + String targetUrl = createTargetContainer(null); + String targetLanguageCode = "fr"; - ClientAuthenticationException e = assertThrows(ClientAuthenticationException.class, - () -> getDTClient(testEndpoint, testApiKey).getSupportedFormats()); + TranslationSource sourceInput = TestHelper.createSourceInput(sourceUrl, null, null, null); + TranslationTarget targetInput = TestHelper.createTargetInput(targetUrl, targetLanguageCode, null, null, null); + List targetInputs = new ArrayList<>(); + targetInputs.add(targetInput); + DocumentTranslationInput batchRequest = new DocumentTranslationInput(sourceInput, targetInputs); + SyncPoller poller = setPlaybackSyncPollerPollInterval( + documentTranslationClient.beginTranslation(TestHelper.getStartTranslationDetails(batchRequest))); - assertEquals(401, e.getResponse().getStatusCode()); + // Wait until the operation completes + TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); + + // Validate the response + validateTranslationStatus(translationStatus, 1); } @RecordWithoutRequestBody @Test - public void testSingleSourceSingleTarget() { + public void testSingleSourceSingleTargetWithImageTranslation() { DocumentTranslationClient documentTranslationClient = getDocumentTranslationClient(); - String sourceUrl = createSourceContainer(ONE_TEST_DOCUMENTS); + // The document embeds an image containing legible text so image scanning has content to translate. + String sourceUrl = createSourceContainerFromFile("test-doc-image.docx"); String targetUrl = createTargetContainer(null); String targetLanguageCode = "fr"; @@ -60,8 +71,10 @@ public void testSingleSourceSingleTarget() { List targetInputs = new ArrayList<>(); targetInputs.add(targetInput); DocumentTranslationInput batchRequest = new DocumentTranslationInput(sourceInput, targetInputs); + + // Enable image translation via the convenience overload. SyncPoller poller = setPlaybackSyncPollerPollInterval( - documentTranslationClient.beginTranslation(TestHelper.getStartTranslationDetails(batchRequest))); + documentTranslationClient.beginTranslation(Arrays.asList(batchRequest), true)); // Wait until the operation completes TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); @@ -319,34 +332,6 @@ public void testRightSourceWrongTarget() { assertEquals("Cannot access target document location with the current permissions.", errorMessage); } - @RecordWithoutRequestBody - @Test - public void testContainerWithSupportedAndUnsupportedFiles() { - DocumentTranslationClient documentTranslationClient = getDocumentTranslationClient(); - List documents = new ArrayList<>(); - documents.add(new TestDocument("Document1.txt", "First english test document")); - documents.add(new TestDocument("File2.jpg", "jpg")); - String sourceUrl = createSourceContainer(documents); - - TranslationSource sourceInput = TestHelper.createSourceInput(sourceUrl, null, null, null); - - String targetUrl = createTargetContainer(null); - String targetLanguageCode = "fr"; - TranslationTarget targetInput = TestHelper.createTargetInput(targetUrl, targetLanguageCode, null, null, null); - List targetInputs = new ArrayList<>(); - targetInputs.add(targetInput); - DocumentTranslationInput batchRequest = new DocumentTranslationInput(sourceInput, targetInputs); - - SyncPoller poller = setPlaybackSyncPollerPollInterval( - documentTranslationClient.beginTranslation(TestHelper.getStartTranslationDetails(batchRequest))); - - // Wait until the operation completes - TranslationStatusResult translationStatus = poller.waitForCompletion().getValue(); - - // Validate the response - validateTranslationStatus(translationStatus, 1); - } - @RecordWithoutRequestBody @Test public void testEmptyDocumentError() { diff --git a/sdk/translation/azure-ai-translation-document/src/test/resources/test-doc-image.docx b/sdk/translation/azure-ai-translation-document/src/test/resources/test-doc-image.docx new file mode 100644 index 000000000000..a5c220411ae7 Binary files /dev/null and b/sdk/translation/azure-ai-translation-document/src/test/resources/test-doc-image.docx differ diff --git a/sdk/translation/azure-ai-translation-document/tsp-location.yaml b/sdk/translation/azure-ai-translation-document/tsp-location.yaml index f664ac92d5da..33b2c74e5294 100644 --- a/sdk/translation/azure-ai-translation-document/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-document/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/data-plane/DocumentTranslation -commit: 6267b64842af3d744c5b092a3f3beef49729ad6d +commit: 53145470a6641f46347ecad9cfdb7961f10b7ff2 repo: Azure/azure-rest-api-specs