@azure-rest/ai-translation-document 1.0.0-alpha.20250227.1 → 1.0.0-alpha.20250303.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -167
- package/dist/browser/clientDefinitions.d.ts +191 -0
- package/dist/browser/clientDefinitions.d.ts.map +1 -0
- package/dist/browser/documentTranslationClient.d.ts +16 -0
- package/dist/browser/documentTranslationClient.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/documentTranslationClient.js +1 -1
- package/dist/browser/documentTranslationClient.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +14 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/isUnexpected.d.ts +10 -0
- package/dist/browser/isUnexpected.d.ts.map +1 -0
- package/dist/browser/logger.d.ts +2 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/models.d.ts +112 -0
- package/dist/browser/models.d.ts.map +1 -0
- package/dist/browser/outputModels.d.ts +166 -0
- package/dist/browser/outputModels.d.ts.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/paginateHelper.d.ts +43 -0
- package/dist/browser/paginateHelper.d.ts.map +1 -0
- package/dist/browser/parameters.d.ts +184 -0
- package/dist/browser/parameters.d.ts.map +1 -0
- package/dist/browser/pollingHelper.d.ts +77 -0
- package/dist/browser/pollingHelper.d.ts.map +1 -0
- package/dist/browser/responses.d.ts +132 -0
- package/dist/browser/responses.d.ts.map +1 -0
- package/dist/commonjs/clientDefinitions.d.ts +191 -0
- package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
- package/dist/commonjs/clientDefinitions.js +3 -0
- package/dist/commonjs/clientDefinitions.js.map +1 -0
- package/dist/commonjs/documentTranslationClient.d.ts +16 -0
- package/dist/commonjs/documentTranslationClient.d.ts.map +1 -0
- package/dist/commonjs/documentTranslationClient.js +45 -0
- package/dist/commonjs/documentTranslationClient.js.map +1 -0
- package/dist/commonjs/index.d.ts +12 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +17 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/isUnexpected.d.ts +10 -0
- package/dist/commonjs/isUnexpected.d.ts.map +1 -0
- package/dist/commonjs/isUnexpected.js +78 -0
- package/dist/commonjs/isUnexpected.js.map +1 -0
- package/dist/commonjs/logger.d.ts +2 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +8 -0
- package/dist/commonjs/logger.js.map +1 -0
- package/dist/commonjs/models.d.ts +112 -0
- package/dist/commonjs/models.d.ts.map +1 -0
- package/dist/commonjs/models.js +5 -0
- package/dist/commonjs/models.js.map +1 -0
- package/dist/commonjs/outputModels.d.ts +166 -0
- package/dist/commonjs/outputModels.d.ts.map +1 -0
- package/dist/commonjs/outputModels.js +5 -0
- package/dist/commonjs/outputModels.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/paginateHelper.d.ts +43 -0
- package/dist/commonjs/paginateHelper.d.ts.map +1 -0
- package/dist/commonjs/paginateHelper.js +71 -0
- package/dist/commonjs/paginateHelper.js.map +1 -0
- package/dist/commonjs/parameters.d.ts +184 -0
- package/dist/commonjs/parameters.d.ts.map +1 -0
- package/dist/commonjs/parameters.js +3 -0
- package/dist/commonjs/parameters.js.map +1 -0
- package/dist/commonjs/pollingHelper.d.ts +77 -0
- package/dist/commonjs/pollingHelper.d.ts.map +1 -0
- package/dist/commonjs/pollingHelper.js +98 -0
- package/dist/commonjs/pollingHelper.js.map +1 -0
- package/dist/commonjs/responses.d.ts +132 -0
- package/dist/commonjs/responses.d.ts.map +1 -0
- package/dist/commonjs/responses.js +3 -0
- package/dist/commonjs/responses.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/clientDefinitions.d.ts +191 -0
- package/dist/esm/clientDefinitions.d.ts.map +1 -0
- package/dist/esm/clientDefinitions.js +2 -0
- package/dist/esm/clientDefinitions.js.map +1 -0
- package/dist/esm/documentTranslationClient.d.ts +16 -0
- package/dist/esm/documentTranslationClient.d.ts.map +1 -0
- package/dist/esm/documentTranslationClient.js +42 -0
- package/dist/esm/documentTranslationClient.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/isUnexpected.d.ts +10 -0
- package/dist/esm/isUnexpected.d.ts.map +1 -0
- package/dist/esm/isUnexpected.js +75 -0
- package/dist/esm/isUnexpected.js.map +1 -0
- package/dist/esm/logger.d.ts +2 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +5 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/models.d.ts +112 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +4 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/outputModels.d.ts +166 -0
- package/dist/esm/outputModels.d.ts.map +1 -0
- package/dist/esm/outputModels.js +4 -0
- package/dist/esm/outputModels.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/paginateHelper.d.ts +43 -0
- package/dist/esm/paginateHelper.d.ts.map +1 -0
- package/dist/esm/paginateHelper.js +68 -0
- package/dist/esm/paginateHelper.js.map +1 -0
- package/dist/esm/parameters.d.ts +184 -0
- package/dist/esm/parameters.d.ts.map +1 -0
- package/dist/esm/parameters.js +2 -0
- package/dist/esm/parameters.js.map +1 -0
- package/dist/esm/pollingHelper.d.ts +77 -0
- package/dist/esm/pollingHelper.d.ts.map +1 -0
- package/dist/esm/pollingHelper.js +95 -0
- package/dist/esm/pollingHelper.js.map +1 -0
- package/dist/esm/responses.d.ts +132 -0
- package/dist/esm/responses.d.ts.map +1 -0
- package/dist/esm/responses.js +2 -0
- package/dist/esm/responses.js.map +1 -0
- package/dist/react-native/clientDefinitions.d.ts +191 -0
- package/dist/react-native/clientDefinitions.d.ts.map +1 -0
- package/dist/react-native/clientDefinitions.js +2 -0
- package/dist/react-native/clientDefinitions.js.map +1 -0
- package/dist/react-native/documentTranslationClient.d.ts +16 -0
- package/dist/react-native/documentTranslationClient.d.ts.map +1 -0
- package/dist/react-native/documentTranslationClient.js +42 -0
- package/dist/react-native/documentTranslationClient.js.map +1 -0
- package/dist/react-native/index.d.ts +12 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +14 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/isUnexpected.d.ts +10 -0
- package/dist/react-native/isUnexpected.d.ts.map +1 -0
- package/dist/react-native/isUnexpected.js +75 -0
- package/dist/react-native/isUnexpected.js.map +1 -0
- package/dist/react-native/logger.d.ts +2 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +5 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/models.d.ts +112 -0
- package/dist/react-native/models.d.ts.map +1 -0
- package/dist/react-native/models.js +4 -0
- package/dist/react-native/models.js.map +1 -0
- package/dist/react-native/outputModels.d.ts +166 -0
- package/dist/react-native/outputModels.d.ts.map +1 -0
- package/dist/react-native/outputModels.js +4 -0
- package/dist/react-native/outputModels.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/paginateHelper.d.ts +43 -0
- package/dist/react-native/paginateHelper.d.ts.map +1 -0
- package/dist/react-native/paginateHelper.js +68 -0
- package/dist/react-native/paginateHelper.js.map +1 -0
- package/dist/react-native/parameters.d.ts +184 -0
- package/dist/react-native/parameters.d.ts.map +1 -0
- package/dist/react-native/parameters.js +2 -0
- package/dist/react-native/parameters.js.map +1 -0
- package/dist/react-native/pollingHelper.d.ts +77 -0
- package/dist/react-native/pollingHelper.d.ts.map +1 -0
- package/dist/react-native/pollingHelper.js +95 -0
- package/dist/react-native/pollingHelper.js.map +1 -0
- package/dist/react-native/responses.d.ts +132 -0
- package/dist/react-native/responses.d.ts.map +1 -0
- package/dist/react-native/responses.js +2 -0
- package/dist/react-native/responses.js.map +1 -0
- package/package.json +68 -43
- package/CHANGELOG.md +0 -34
- package/dist/index.js +0 -293
- package/dist/index.js.map +0 -1
- package/dist-esm/src/documentTranslationClient.js.map +0 -1
- package/dist-esm/src/index.js +0 -14
- package/dist-esm/src/index.js.map +0 -1
- package/types/ai-translation-document.d.ts +0 -1018
- /package/{dist-esm/src → dist/browser}/clientDefinitions.js +0 -0
- /package/{dist-esm/src → dist/browser}/clientDefinitions.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/isUnexpected.js +0 -0
- /package/{dist-esm/src → dist/browser}/isUnexpected.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/logger.js +0 -0
- /package/{dist-esm/src → dist/browser}/logger.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/models.js +0 -0
- /package/{dist-esm/src → dist/browser}/models.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/outputModels.js +0 -0
- /package/{dist-esm/src → dist/browser}/outputModels.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/paginateHelper.js +0 -0
- /package/{dist-esm/src → dist/browser}/paginateHelper.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/parameters.js +0 -0
- /package/{dist-esm/src → dist/browser}/parameters.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/pollingHelper.js +0 -0
- /package/{dist-esm/src → dist/browser}/pollingHelper.js.map +0 -0
- /package/{dist-esm/src → dist/browser}/responses.js +0 -0
- /package/{dist-esm/src → dist/browser}/responses.js.map +0 -0
package/README.md
CHANGED
|
@@ -54,21 +54,33 @@ npm install @azure-rest/ai-translation-document
|
|
|
54
54
|
You can create Translator resource following [Create a Translator resource][translator_resource_create].
|
|
55
55
|
|
|
56
56
|
#### Setup Azure Blob Storage Account
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
For more information about creating an Azure Blob Storage account see [here][azure_blob_storage_account]. For creating containers for your source and target files see [here][container]. Make sure to authorize your Translation resource storage access, more info [here][storage_container_authorization].
|
|
58
59
|
|
|
59
60
|
When "Allow Storage Account Key Access" is disabled on the storage account , Managed Identity is enabled on the Translator resource and it is assigned the role "Storage Blob Data Contributor" on the storage account, then you can use the container URLs directly and no SAS URIs will be need to be generated.
|
|
60
61
|
|
|
61
62
|
### Create a `DocumentTranslationClient` using an endpoint URL and API key `KeyCredential`
|
|
62
63
|
|
|
63
64
|
Once you have the value for API key, create a credential
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
|
|
66
|
+
```ts snippet:ReadmeSampleKeyCredential
|
|
67
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
68
|
+
const credential = {
|
|
69
|
+
key,
|
|
70
|
+
};
|
|
66
71
|
```
|
|
67
72
|
|
|
68
73
|
With the value of the `KeyCredential` you can create the `DocumentTranslationClient` using the `createClient` method of [documentTranslationClient_class]:
|
|
69
74
|
|
|
70
|
-
```
|
|
71
|
-
|
|
75
|
+
```ts snippet:ReadmeSampleCreateClient
|
|
76
|
+
import DocumentTranslationClient from "@azure-rest/ai-translation-document";
|
|
77
|
+
|
|
78
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
79
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
80
|
+
const credential = {
|
|
81
|
+
key,
|
|
82
|
+
};
|
|
83
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
72
84
|
```
|
|
73
85
|
|
|
74
86
|
## Examples
|
|
@@ -79,9 +91,20 @@ The following section provides several code snippets using the `client`, and cov
|
|
|
79
91
|
|
|
80
92
|
Used to synchronously translate a single document. The method doesn't require an Azure Blob storage account.
|
|
81
93
|
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
```ts snippet:ReadmeSampleSynchronousDocumentTranslation
|
|
95
|
+
import DocumentTranslationClient, {
|
|
96
|
+
DocumentTranslateParameters,
|
|
97
|
+
isUnexpected,
|
|
98
|
+
} from "@azure-rest/ai-translation-document";
|
|
99
|
+
import { writeFileSync } from "node:fs";
|
|
100
|
+
|
|
101
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
102
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
103
|
+
const credential = {
|
|
104
|
+
key,
|
|
105
|
+
};
|
|
106
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
107
|
+
|
|
85
108
|
const options: DocumentTranslateParameters = {
|
|
86
109
|
queryParameters: {
|
|
87
110
|
targetLanguage: "hi",
|
|
@@ -99,229 +122,266 @@ const options: DocumentTranslateParameters = {
|
|
|
99
122
|
|
|
100
123
|
const response = await client.path("/document:translate").post(options);
|
|
101
124
|
if (isUnexpected(response)) {
|
|
102
|
-
throw response.body;
|
|
125
|
+
throw response.body.error;
|
|
103
126
|
}
|
|
104
|
-
|
|
127
|
+
|
|
128
|
+
// Write the response to a file
|
|
129
|
+
writeFileSync("test-output.txt", response.body);
|
|
105
130
|
```
|
|
106
131
|
|
|
107
132
|
### Batch Document Translation
|
|
133
|
+
|
|
108
134
|
Used to execute an asynchronous batch translation request. The method requires an Azure Blob storage account with storage containers for your source and translated documents.
|
|
109
135
|
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
136
|
+
```ts snippet:ReadmeSampleBatchDocumentTranslation
|
|
137
|
+
import DocumentTranslationClient from "@azure-rest/ai-translation-document";
|
|
138
|
+
import { BlobServiceClient, ContainerSASPermissions } from "@azure/storage-blob";
|
|
139
|
+
|
|
140
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
141
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
142
|
+
const credential = {
|
|
143
|
+
key,
|
|
144
|
+
};
|
|
145
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
146
|
+
|
|
147
|
+
// Upload test documents to source container
|
|
148
|
+
const testDocuments = [{ name: "Document1.txt", content: "First english test document" }];
|
|
149
|
+
const sourceContainerName = "source-12345";
|
|
150
|
+
const connectionString =
|
|
151
|
+
"DefaultEndpointsProtocol=httpsAccountName=your_account_name;AccountKey=your_account_key;EndpointSuffix=core.windows.net";
|
|
152
|
+
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
|
|
153
|
+
const sourceContainerClient = blobServiceClient.getContainerClient(sourceContainerName);
|
|
154
|
+
await sourceContainerClient.createIfNotExists();
|
|
155
|
+
for (const document of testDocuments) {
|
|
156
|
+
const blobClient = sourceContainerClient.getBlobClient(document.name);
|
|
157
|
+
const blockBlobClient = blobClient.getBlockBlobClient();
|
|
158
|
+
await blockBlobClient.upload(document.content, document.content.length);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Create configuration for the source connection
|
|
162
|
+
const sourceUrl = await sourceContainerClient.generateSasUrl({
|
|
163
|
+
permissions: ContainerSASPermissions.parse("rwl"),
|
|
164
|
+
expiresOn: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
|
165
|
+
});
|
|
166
|
+
const sourceInput = { sourceUrl };
|
|
167
|
+
|
|
168
|
+
// Create target container
|
|
169
|
+
const targetContainerName = "target-12345";
|
|
170
|
+
const targetContainerClient = blobServiceClient.getContainerClient(targetContainerName);
|
|
171
|
+
await targetContainerClient.createIfNotExists();
|
|
113
172
|
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
// Create configuration for the target connection
|
|
174
|
+
const targetUrl = await targetContainerClient.generateSasUrl({
|
|
175
|
+
permissions: ContainerSASPermissions.parse("rwl"),
|
|
176
|
+
expiresOn: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
|
177
|
+
});
|
|
178
|
+
const targetInput = { targetUrl, language: "fr" };
|
|
119
179
|
|
|
120
|
-
//Start translation
|
|
121
|
-
const
|
|
180
|
+
// Start translation
|
|
181
|
+
const batchRequest = { source: sourceInput, targets: [targetInput] };
|
|
182
|
+
const batchRequests = { inputs: [batchRequest] };
|
|
122
183
|
const poller = await client.path("/document/batches").post({
|
|
123
|
-
body: batchRequests
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
|
|
184
|
+
body: batchRequests,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const operationId =
|
|
188
|
+
new URL(poller.headers["operation-location"]).pathname.split("/").filter(Boolean).pop() || "";
|
|
189
|
+
console.log(`Translation started and the operationID is: ${operationId}`);
|
|
127
190
|
```
|
|
128
191
|
|
|
129
192
|
### Cancel Document Translation
|
|
130
|
-
This cancels a translation job that is currently processing or queued (pending) as indicated in the request by the id query parameter. An operation isn't canceled if already completed, failed, or still canceling. In those instances, a bad request is returned. Completed translations can't be canceled and are charged.
|
|
131
193
|
|
|
132
|
-
|
|
133
|
-
console.log("== Cancel Translation ==");
|
|
134
|
-
const client = createClient(endpoint, credentials);
|
|
194
|
+
This cancels a translation job that is currently processing or queued (pending) as indicated in the request by the id query parameter. An operation isn't canceled if already completed, failed, or still canceling. In those instances, a bad request is returned. Completed translations can't be canceled and are charged.
|
|
135
195
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const targetUrl = await createTargetContainer();
|
|
139
|
-
const targetInput = createTargetInput(targetUrl, "fr");
|
|
140
|
-
const batchRequest = createBatchRequest(sourceInput, [targetInput]);
|
|
196
|
+
```ts snippet:ReadmeSampleCancelDocumentTranslation
|
|
197
|
+
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
141
198
|
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
const
|
|
199
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
200
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
201
|
+
const credential = {
|
|
202
|
+
key,
|
|
203
|
+
};
|
|
204
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
148
205
|
|
|
149
|
-
|
|
206
|
+
const id = "<operation-id-from-batch-translation>";
|
|
150
207
|
await client.path("/document/batches/{id}", id).delete();
|
|
151
208
|
|
|
152
|
-
//
|
|
209
|
+
// Get translation status and verify the job is cancelled, cancelling or notStarted
|
|
153
210
|
const response = await client.path("/document/batches/{id}", id).get();
|
|
154
211
|
if (isUnexpected(response)) {
|
|
155
|
-
throw response.body;
|
|
212
|
+
throw response.body.error;
|
|
156
213
|
}
|
|
157
|
-
console.log("The status after cancelling the batch operation is:" + response.body.status);
|
|
158
214
|
```
|
|
159
215
|
|
|
160
216
|
### Get Documents Status
|
|
161
|
-
Used to request the status for all documents in a translation job.
|
|
162
217
|
|
|
163
|
-
|
|
164
|
-
console.log("== Gets Documents Status ==");
|
|
165
|
-
const client = createClient(endpoint, credentials);
|
|
166
|
-
|
|
167
|
-
const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
|
|
168
|
-
const sourceInput = createSourceInput(sourceUrl);
|
|
169
|
-
const targetUrl = await createTargetContainer();
|
|
170
|
-
const targetInput = createTargetInput(targetUrl, "fr");
|
|
171
|
-
const batchRequest = createBatchRequest(sourceInput, [targetInput]);
|
|
218
|
+
Used to request the status for all documents in a translation job.
|
|
172
219
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
220
|
+
```ts snippet:ReadmeSampleGetDocumentsStatus
|
|
221
|
+
import DocumentTranslationClient, {
|
|
222
|
+
isUnexpected,
|
|
223
|
+
paginate,
|
|
224
|
+
} from "@azure-rest/ai-translation-document";
|
|
176
225
|
|
|
177
|
-
const
|
|
178
|
-
const
|
|
226
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
227
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
228
|
+
const credential = {
|
|
229
|
+
key,
|
|
230
|
+
};
|
|
231
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
179
232
|
|
|
180
|
-
//
|
|
181
|
-
const
|
|
233
|
+
// Get Documents Status
|
|
234
|
+
const id = "<operation-id-from-batch-translation>";
|
|
235
|
+
const documentResponse = await client.path("/document/batches/{id}/documents", id).get();
|
|
182
236
|
if (isUnexpected(documentResponse)) {
|
|
183
|
-
throw documentResponse.body;
|
|
237
|
+
throw documentResponse.body.error;
|
|
184
238
|
}
|
|
185
239
|
|
|
186
|
-
const
|
|
187
|
-
for (const
|
|
188
|
-
|
|
189
|
-
console.log("Characters charged is: " + documentStatus.characterCharged);
|
|
190
|
-
break;
|
|
240
|
+
const documentStatus = paginate(client, documentResponse);
|
|
241
|
+
for await (const document of documentStatus) {
|
|
242
|
+
console.log(`Document ${document.id} status: ${document.status}`);
|
|
191
243
|
}
|
|
192
244
|
```
|
|
193
245
|
|
|
194
246
|
### Get Document Status
|
|
195
|
-
This returns the status for a specific document in a job as indicated in the request by the id and documentId query parameters.
|
|
196
247
|
|
|
197
|
-
|
|
198
|
-
console.log("== Get Document Status ==");
|
|
199
|
-
const client = createClient(endpoint, credentials);
|
|
248
|
+
This returns the status for a specific document in a job as indicated in the request by the id and documentId query parameters.
|
|
200
249
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
250
|
+
```ts snippet:ReadmeSampleGetDocumentStatus
|
|
251
|
+
import DocumentTranslationClient, {
|
|
252
|
+
isUnexpected,
|
|
253
|
+
paginate,
|
|
254
|
+
} from "@azure-rest/ai-translation-document";
|
|
206
255
|
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
256
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
257
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
258
|
+
const credential = {
|
|
259
|
+
key,
|
|
260
|
+
};
|
|
261
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
212
262
|
|
|
213
|
-
//
|
|
214
|
-
const
|
|
263
|
+
// Get Documents Status
|
|
264
|
+
const id = "<operation-id-from-batch-translation>";
|
|
265
|
+
const documentResponse = await client.path("/document/batches/{id}/documents", id).get();
|
|
215
266
|
if (isUnexpected(documentResponse)) {
|
|
216
|
-
throw documentResponse.body;
|
|
267
|
+
throw documentResponse.body.error;
|
|
217
268
|
}
|
|
218
269
|
|
|
219
|
-
const
|
|
220
|
-
for (const document of
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
270
|
+
const documentStatus = paginate(client, documentResponse);
|
|
271
|
+
for await (const document of documentStatus) {
|
|
272
|
+
// Get individual Document Status
|
|
273
|
+
const documentStatus = await client
|
|
274
|
+
.path("/document/batches/{id}/documents/{documentId}", id, document.id)
|
|
275
|
+
.get();
|
|
276
|
+
if (isUnexpected(documentStatus)) {
|
|
277
|
+
throw documentStatus.body.error;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const documentStatusOutput = documentStatus.body;
|
|
281
|
+
console.log(`Document Status: ${documentStatusOutput.status}`);
|
|
282
|
+
console.log(`Document ID: ${documentStatusOutput.id}`);
|
|
283
|
+
console.log(`Document source path: ${documentStatusOutput.sourcePath}`);
|
|
284
|
+
console.log(`Document path: ${documentStatusOutput.path}`);
|
|
285
|
+
console.log(`Target language: ${documentStatusOutput.to}`);
|
|
286
|
+
console.log(`Document created dateTime: ${documentStatusOutput.createdDateTimeUtc}`);
|
|
287
|
+
console.log(`Document last action date time: ${documentStatusOutput.lastActionDateTimeUtc}`);
|
|
231
288
|
}
|
|
232
289
|
```
|
|
233
290
|
|
|
234
291
|
### Get Translations Status
|
|
292
|
+
|
|
235
293
|
Used to request a list and the status of all translation jobs submitted by the user (associated with the resource).
|
|
236
294
|
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
295
|
+
```ts snippet:ReadmeSampleGetTranslationsStatus
|
|
296
|
+
import DocumentTranslationClient, {
|
|
297
|
+
isUnexpected,
|
|
298
|
+
paginate,
|
|
299
|
+
} from "@azure-rest/ai-translation-document";
|
|
300
|
+
|
|
301
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
302
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
303
|
+
const credential = {
|
|
304
|
+
key,
|
|
305
|
+
};
|
|
306
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
307
|
+
|
|
308
|
+
// Get status
|
|
309
|
+
const id = "<operation-id-from-batch-translation>";
|
|
310
|
+
const queryParams = {
|
|
311
|
+
ids: [id],
|
|
312
|
+
};
|
|
313
|
+
const response = await client.path("/document/batches").get({
|
|
314
|
+
queryParameters: queryParams,
|
|
315
|
+
});
|
|
316
|
+
if (isUnexpected(response)) {
|
|
317
|
+
throw response.body.error;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const translationResponse = paginate(client, response);
|
|
321
|
+
for await (const translationStatus of translationResponse) {
|
|
322
|
+
console.log(`Translation ID: ${translationStatus.id}`);
|
|
323
|
+
console.log(`Translation Status ${translationStatus.status}`);
|
|
324
|
+
console.log(`Translation createdDateTimeUtc: ${translationStatus.createdDateTimeUtc}`);
|
|
325
|
+
console.log(`Translation lastActionDateTimeUtc: ${translationStatus.lastActionDateTimeUtc}`);
|
|
326
|
+
console.log(`Total documents submitted for translation: ${translationStatus.summary.total}`);
|
|
327
|
+
console.log(`Total characters charged: ${translationStatus.summary.totalCharacterCharged}`);
|
|
328
|
+
}
|
|
272
329
|
```
|
|
273
330
|
|
|
274
331
|
### Get Translation Status
|
|
275
|
-
Used to request the status of a specific translation job. The response includes the overall job status and the status for documents that are being translated as part of that job.
|
|
276
|
-
|
|
277
|
-
```typescript
|
|
278
|
-
console.log("== Get Translation Status ==");
|
|
279
|
-
const client = createClient(endpoint, credentials);
|
|
280
332
|
|
|
281
|
-
|
|
282
|
-
const sourceInput = createSourceInput(sourceUrl);
|
|
283
|
-
const targetUrl = await createTargetContainer();
|
|
284
|
-
const targetInput = createTargetInput(targetUrl, "fr");
|
|
285
|
-
const batchRequest = createBatchRequest(sourceInput, [targetInput]);
|
|
333
|
+
Used to request the status of a specific translation job. The response includes the overall job status and the status for documents that are being translated as part of that job.
|
|
286
334
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const translationResponse = await StartTranslationAndWait(client, batchRequests);
|
|
335
|
+
```ts snippet:ReadmeSampleGetTranslationStatus
|
|
336
|
+
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
290
337
|
|
|
291
|
-
const
|
|
292
|
-
const
|
|
338
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
339
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
340
|
+
const credential = {
|
|
341
|
+
key,
|
|
342
|
+
};
|
|
343
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
293
344
|
|
|
294
|
-
//
|
|
295
|
-
const
|
|
345
|
+
// Get status
|
|
346
|
+
const id = "<operation-id-from-batch-translation>";
|
|
347
|
+
const response = await client.path("/document/batches/{id}", id).get();
|
|
296
348
|
if (isUnexpected(response)) {
|
|
297
|
-
|
|
349
|
+
throw response.body.error;
|
|
298
350
|
}
|
|
299
351
|
|
|
300
|
-
|
|
301
|
-
console.log(
|
|
302
|
-
console.log(
|
|
303
|
-
console.log(
|
|
304
|
-
console.log(
|
|
305
|
-
console.log(
|
|
352
|
+
const translationStatus = response.body;
|
|
353
|
+
console.log(`Translation ID: ${translationStatus.id}`);
|
|
354
|
+
console.log(`Translation Status ${translationStatus.status}`);
|
|
355
|
+
console.log(`Translation createdDateTimeUtc: ${translationStatus.createdDateTimeUtc}`);
|
|
356
|
+
console.log(`Translation lastActionDateTimeUtc: ${translationStatus.lastActionDateTimeUtc}`);
|
|
357
|
+
console.log(`Total documents submitted for translation: ${translationStatus.summary.total}`);
|
|
358
|
+
console.log(`Total characters charged: ${translationStatus.summary.totalCharacterCharged}`);
|
|
306
359
|
```
|
|
307
360
|
|
|
308
|
-
|
|
309
361
|
### Get Supported Formats
|
|
310
362
|
|
|
311
363
|
This returns a list of document or glossary formats supported by the Document Translation feature. The list includes common file extensions and content-type if using the upload API.
|
|
312
364
|
|
|
313
|
-
```
|
|
314
|
-
|
|
365
|
+
```ts snippet:ReadmeSampleGetSupportedFormats
|
|
366
|
+
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
315
367
|
|
|
316
|
-
const
|
|
317
|
-
const
|
|
368
|
+
const endpoint = "https://<translator-instance>-doctranslation.cognitiveservices.azure.com";
|
|
369
|
+
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
370
|
+
const credential = {
|
|
371
|
+
key,
|
|
372
|
+
};
|
|
373
|
+
const client = DocumentTranslationClient(endpoint, credential);
|
|
318
374
|
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
375
|
+
const response = await client.path("/document/formats").get();
|
|
376
|
+
if (isUnexpected(response)) {
|
|
377
|
+
throw response.body.error;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
for (const fileFormatType of response.body.value) {
|
|
381
|
+
console.log(`File format: ${fileFormatType.format}`);
|
|
382
|
+
console.log(`Content types: ${fileFormatType.contentTypes}`);
|
|
383
|
+
console.log(`File extensions: ${fileFormatType.fileExtensions}`);
|
|
384
|
+
}
|
|
325
385
|
```
|
|
326
386
|
|
|
327
387
|
## Troubleshooting
|
|
@@ -336,8 +396,8 @@ You can find the different error codes returned by the service in the [Service D
|
|
|
336
396
|
|
|
337
397
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
338
398
|
|
|
339
|
-
```
|
|
340
|
-
|
|
399
|
+
```ts snippet:SetLogLevel
|
|
400
|
+
import { setLogLevel } from "@azure/logger";
|
|
341
401
|
|
|
342
402
|
setLogLevel("info");
|
|
343
403
|
```
|