@azure-rest/ai-translation-document 1.0.0-alpha.20250226.1 → 1.0.0-alpha.20250228.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.
Files changed (190) hide show
  1. package/README.md +227 -167
  2. package/dist/browser/clientDefinitions.d.ts +191 -0
  3. package/dist/browser/clientDefinitions.d.ts.map +1 -0
  4. package/dist/browser/documentTranslationClient.d.ts +16 -0
  5. package/dist/browser/documentTranslationClient.d.ts.map +1 -0
  6. package/{dist-esm/src → dist/browser}/documentTranslationClient.js +1 -1
  7. package/dist/browser/documentTranslationClient.js.map +1 -0
  8. package/dist/browser/index.d.ts +12 -0
  9. package/dist/browser/index.d.ts.map +1 -0
  10. package/dist/browser/index.js +14 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/isUnexpected.d.ts +10 -0
  13. package/dist/browser/isUnexpected.d.ts.map +1 -0
  14. package/dist/browser/logger.d.ts +2 -0
  15. package/dist/browser/logger.d.ts.map +1 -0
  16. package/dist/browser/models.d.ts +112 -0
  17. package/dist/browser/models.d.ts.map +1 -0
  18. package/dist/browser/outputModels.d.ts +166 -0
  19. package/dist/browser/outputModels.d.ts.map +1 -0
  20. package/dist/browser/package.json +3 -0
  21. package/dist/browser/paginateHelper.d.ts +43 -0
  22. package/dist/browser/paginateHelper.d.ts.map +1 -0
  23. package/dist/browser/parameters.d.ts +184 -0
  24. package/dist/browser/parameters.d.ts.map +1 -0
  25. package/dist/browser/pollingHelper.d.ts +77 -0
  26. package/dist/browser/pollingHelper.d.ts.map +1 -0
  27. package/dist/browser/responses.d.ts +132 -0
  28. package/dist/browser/responses.d.ts.map +1 -0
  29. package/dist/commonjs/clientDefinitions.d.ts +191 -0
  30. package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
  31. package/dist/commonjs/clientDefinitions.js +3 -0
  32. package/dist/commonjs/clientDefinitions.js.map +1 -0
  33. package/dist/commonjs/documentTranslationClient.d.ts +16 -0
  34. package/dist/commonjs/documentTranslationClient.d.ts.map +1 -0
  35. package/dist/commonjs/documentTranslationClient.js +45 -0
  36. package/dist/commonjs/documentTranslationClient.js.map +1 -0
  37. package/dist/commonjs/index.d.ts +12 -0
  38. package/dist/commonjs/index.d.ts.map +1 -0
  39. package/dist/commonjs/index.js +17 -0
  40. package/dist/commonjs/index.js.map +1 -0
  41. package/dist/commonjs/isUnexpected.d.ts +10 -0
  42. package/dist/commonjs/isUnexpected.d.ts.map +1 -0
  43. package/dist/commonjs/isUnexpected.js +78 -0
  44. package/dist/commonjs/isUnexpected.js.map +1 -0
  45. package/dist/commonjs/logger.d.ts +2 -0
  46. package/dist/commonjs/logger.d.ts.map +1 -0
  47. package/dist/commonjs/logger.js +8 -0
  48. package/dist/commonjs/logger.js.map +1 -0
  49. package/dist/commonjs/models.d.ts +112 -0
  50. package/dist/commonjs/models.d.ts.map +1 -0
  51. package/dist/commonjs/models.js +5 -0
  52. package/dist/commonjs/models.js.map +1 -0
  53. package/dist/commonjs/outputModels.d.ts +166 -0
  54. package/dist/commonjs/outputModels.d.ts.map +1 -0
  55. package/dist/commonjs/outputModels.js +5 -0
  56. package/dist/commonjs/outputModels.js.map +1 -0
  57. package/dist/commonjs/package.json +3 -0
  58. package/dist/commonjs/paginateHelper.d.ts +43 -0
  59. package/dist/commonjs/paginateHelper.d.ts.map +1 -0
  60. package/dist/commonjs/paginateHelper.js +71 -0
  61. package/dist/commonjs/paginateHelper.js.map +1 -0
  62. package/dist/commonjs/parameters.d.ts +184 -0
  63. package/dist/commonjs/parameters.d.ts.map +1 -0
  64. package/dist/commonjs/parameters.js +3 -0
  65. package/dist/commonjs/parameters.js.map +1 -0
  66. package/dist/commonjs/pollingHelper.d.ts +77 -0
  67. package/dist/commonjs/pollingHelper.d.ts.map +1 -0
  68. package/dist/commonjs/pollingHelper.js +98 -0
  69. package/dist/commonjs/pollingHelper.js.map +1 -0
  70. package/dist/commonjs/responses.d.ts +132 -0
  71. package/dist/commonjs/responses.d.ts.map +1 -0
  72. package/dist/commonjs/responses.js +3 -0
  73. package/dist/commonjs/responses.js.map +1 -0
  74. package/dist/commonjs/tsdoc-metadata.json +11 -0
  75. package/dist/esm/clientDefinitions.d.ts +191 -0
  76. package/dist/esm/clientDefinitions.d.ts.map +1 -0
  77. package/dist/esm/clientDefinitions.js +2 -0
  78. package/dist/esm/clientDefinitions.js.map +1 -0
  79. package/dist/esm/documentTranslationClient.d.ts +16 -0
  80. package/dist/esm/documentTranslationClient.d.ts.map +1 -0
  81. package/dist/esm/documentTranslationClient.js +42 -0
  82. package/dist/esm/documentTranslationClient.js.map +1 -0
  83. package/dist/esm/index.d.ts +12 -0
  84. package/dist/esm/index.d.ts.map +1 -0
  85. package/dist/esm/index.js +14 -0
  86. package/dist/esm/index.js.map +1 -0
  87. package/dist/esm/isUnexpected.d.ts +10 -0
  88. package/dist/esm/isUnexpected.d.ts.map +1 -0
  89. package/dist/esm/isUnexpected.js +75 -0
  90. package/dist/esm/isUnexpected.js.map +1 -0
  91. package/dist/esm/logger.d.ts +2 -0
  92. package/dist/esm/logger.d.ts.map +1 -0
  93. package/dist/esm/logger.js +5 -0
  94. package/dist/esm/logger.js.map +1 -0
  95. package/dist/esm/models.d.ts +112 -0
  96. package/dist/esm/models.d.ts.map +1 -0
  97. package/dist/esm/models.js +4 -0
  98. package/dist/esm/models.js.map +1 -0
  99. package/dist/esm/outputModels.d.ts +166 -0
  100. package/dist/esm/outputModels.d.ts.map +1 -0
  101. package/dist/esm/outputModels.js +4 -0
  102. package/dist/esm/outputModels.js.map +1 -0
  103. package/dist/esm/package.json +3 -0
  104. package/dist/esm/paginateHelper.d.ts +43 -0
  105. package/dist/esm/paginateHelper.d.ts.map +1 -0
  106. package/dist/esm/paginateHelper.js +68 -0
  107. package/dist/esm/paginateHelper.js.map +1 -0
  108. package/dist/esm/parameters.d.ts +184 -0
  109. package/dist/esm/parameters.d.ts.map +1 -0
  110. package/dist/esm/parameters.js +2 -0
  111. package/dist/esm/parameters.js.map +1 -0
  112. package/dist/esm/pollingHelper.d.ts +77 -0
  113. package/dist/esm/pollingHelper.d.ts.map +1 -0
  114. package/dist/esm/pollingHelper.js +95 -0
  115. package/dist/esm/pollingHelper.js.map +1 -0
  116. package/dist/esm/responses.d.ts +132 -0
  117. package/dist/esm/responses.d.ts.map +1 -0
  118. package/dist/esm/responses.js +2 -0
  119. package/dist/esm/responses.js.map +1 -0
  120. package/dist/react-native/clientDefinitions.d.ts +191 -0
  121. package/dist/react-native/clientDefinitions.d.ts.map +1 -0
  122. package/dist/react-native/clientDefinitions.js +2 -0
  123. package/dist/react-native/clientDefinitions.js.map +1 -0
  124. package/dist/react-native/documentTranslationClient.d.ts +16 -0
  125. package/dist/react-native/documentTranslationClient.d.ts.map +1 -0
  126. package/dist/react-native/documentTranslationClient.js +42 -0
  127. package/dist/react-native/documentTranslationClient.js.map +1 -0
  128. package/dist/react-native/index.d.ts +12 -0
  129. package/dist/react-native/index.d.ts.map +1 -0
  130. package/dist/react-native/index.js +14 -0
  131. package/dist/react-native/index.js.map +1 -0
  132. package/dist/react-native/isUnexpected.d.ts +10 -0
  133. package/dist/react-native/isUnexpected.d.ts.map +1 -0
  134. package/dist/react-native/isUnexpected.js +75 -0
  135. package/dist/react-native/isUnexpected.js.map +1 -0
  136. package/dist/react-native/logger.d.ts +2 -0
  137. package/dist/react-native/logger.d.ts.map +1 -0
  138. package/dist/react-native/logger.js +5 -0
  139. package/dist/react-native/logger.js.map +1 -0
  140. package/dist/react-native/models.d.ts +112 -0
  141. package/dist/react-native/models.d.ts.map +1 -0
  142. package/dist/react-native/models.js +4 -0
  143. package/dist/react-native/models.js.map +1 -0
  144. package/dist/react-native/outputModels.d.ts +166 -0
  145. package/dist/react-native/outputModels.d.ts.map +1 -0
  146. package/dist/react-native/outputModels.js +4 -0
  147. package/dist/react-native/outputModels.js.map +1 -0
  148. package/dist/react-native/package.json +3 -0
  149. package/dist/react-native/paginateHelper.d.ts +43 -0
  150. package/dist/react-native/paginateHelper.d.ts.map +1 -0
  151. package/dist/react-native/paginateHelper.js +68 -0
  152. package/dist/react-native/paginateHelper.js.map +1 -0
  153. package/dist/react-native/parameters.d.ts +184 -0
  154. package/dist/react-native/parameters.d.ts.map +1 -0
  155. package/dist/react-native/parameters.js +2 -0
  156. package/dist/react-native/parameters.js.map +1 -0
  157. package/dist/react-native/pollingHelper.d.ts +77 -0
  158. package/dist/react-native/pollingHelper.d.ts.map +1 -0
  159. package/dist/react-native/pollingHelper.js +95 -0
  160. package/dist/react-native/pollingHelper.js.map +1 -0
  161. package/dist/react-native/responses.d.ts +132 -0
  162. package/dist/react-native/responses.d.ts.map +1 -0
  163. package/dist/react-native/responses.js +2 -0
  164. package/dist/react-native/responses.js.map +1 -0
  165. package/package.json +68 -43
  166. package/CHANGELOG.md +0 -34
  167. package/dist/index.js +0 -293
  168. package/dist/index.js.map +0 -1
  169. package/dist-esm/src/documentTranslationClient.js.map +0 -1
  170. package/dist-esm/src/index.js +0 -14
  171. package/dist-esm/src/index.js.map +0 -1
  172. package/types/ai-translation-document.d.ts +0 -1018
  173. /package/{dist-esm/src → dist/browser}/clientDefinitions.js +0 -0
  174. /package/{dist-esm/src → dist/browser}/clientDefinitions.js.map +0 -0
  175. /package/{dist-esm/src → dist/browser}/isUnexpected.js +0 -0
  176. /package/{dist-esm/src → dist/browser}/isUnexpected.js.map +0 -0
  177. /package/{dist-esm/src → dist/browser}/logger.js +0 -0
  178. /package/{dist-esm/src → dist/browser}/logger.js.map +0 -0
  179. /package/{dist-esm/src → dist/browser}/models.js +0 -0
  180. /package/{dist-esm/src → dist/browser}/models.js.map +0 -0
  181. /package/{dist-esm/src → dist/browser}/outputModels.js +0 -0
  182. /package/{dist-esm/src → dist/browser}/outputModels.js.map +0 -0
  183. /package/{dist-esm/src → dist/browser}/paginateHelper.js +0 -0
  184. /package/{dist-esm/src → dist/browser}/paginateHelper.js.map +0 -0
  185. /package/{dist-esm/src → dist/browser}/parameters.js +0 -0
  186. /package/{dist-esm/src → dist/browser}/parameters.js.map +0 -0
  187. /package/{dist-esm/src → dist/browser}/pollingHelper.js +0 -0
  188. /package/{dist-esm/src → dist/browser}/pollingHelper.js.map +0 -0
  189. /package/{dist-esm/src → dist/browser}/responses.js +0 -0
  190. /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
- 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].
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
- ```typescript
65
- const credentials = { key: apiKey ?? "" };
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
- ```typescript
71
- const client = createClient(endpoint, credentials);
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
- ```typescript
83
- console.log("== Synchronous Document Translation ==");
84
- const client = createClient(endpoint, credentials);
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
- console.log('Response code: ' + response.status + ', Response body: ' + response.body);
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
- ```typescript
111
- console.log("== Batch Document Translation ==");
112
- const client = createClient(endpoint, credentials);
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
- const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
115
- const sourceInput = createSourceInput(sourceUrl);
116
- const targetUrl = await createTargetContainer();
117
- const targetInput = createTargetInput(targetUrl, "fr");
118
- const batchRequest = createBatchRequest(sourceInput, [targetInput]);
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 batchRequests = {inputs: [batchRequest]};
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
- const id = getTranslationOperationID(poller.headers["operation-location"]);
126
- console.log('Translation started and the operationID is: ' + id);
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
- ```typescript
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
- const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
137
- const sourceInput = createSourceInput(sourceUrl);
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
- //Start translation
143
- const batchRequests = {inputs: [batchRequest]};
144
- const poller = await client.path("/document/batches").post({
145
- body: batchRequests
146
- });
147
- const id = getTranslationOperationID(poller.headers["operation-location"]);
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
- //Cancel translation
206
+ const id = "<operation-id-from-batch-translation>";
150
207
  await client.path("/document/batches/{id}", id).delete();
151
208
 
152
- //get translation status and verify the job is cancelled, cancelling or notStarted
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
- ```typescript
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
- //Start translation
174
- const batchRequests = {inputs: [batchRequest]};
175
- const response = await StartTranslationAndWait(client, batchRequests);
220
+ ```ts snippet:ReadmeSampleGetDocumentsStatus
221
+ import DocumentTranslationClient, {
222
+ isUnexpected,
223
+ paginate,
224
+ } from "@azure-rest/ai-translation-document";
176
225
 
177
- const operationLocationUrl = response.headers["operation-location"]
178
- const operationId = getTranslationOperationID(operationLocationUrl);
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
- //get Documents Status
181
- const documentResponse = await client.path("/document/batches/{id}/documents", operationId).get();
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 responseBody = documentResponse.body;
187
- for (const documentStatus of responseBody.value) {
188
- console.log("Document Status is: " + documentStatus.status);
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
- ```typescript
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
- const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
202
- const sourceInput = createSourceInput(sourceUrl);
203
- const targetUrl = await createTargetContainer();
204
- const targetInput = createTargetInput(targetUrl, "fr");
205
- const batchRequest = createBatchRequest(sourceInput, [targetInput]);
250
+ ```ts snippet:ReadmeSampleGetDocumentStatus
251
+ import DocumentTranslationClient, {
252
+ isUnexpected,
253
+ paginate,
254
+ } from "@azure-rest/ai-translation-document";
206
255
 
207
- //Start translation
208
- const batchRequests = {inputs: [batchRequest]};
209
- const response = await StartTranslationAndWait(client, batchRequests);
210
- const operationLocationUrl = response.headers["operation-location"]
211
- const operationId = getTranslationOperationID(operationLocationUrl);
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
- //get Documents Status
214
- const documentResponse = await client.path("/document/batches/{id}/documents", operationId).get();
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 responseBody = documentResponse.body;
220
- for (const document of responseBody.value) {
221
- //get document status
222
- const documentStatus = await client.path("/document/batches/{id}/documents/{documentId}", operationId, document.id).get();
223
- console.log("Document Status = " + documentStatus.status);
224
- const documentStatusOutput = documentStatus.body as DocumentStatusOutput;
225
- console.log("Document ID = " +documentStatusOutput.id);
226
- console.log("Document source path = " + documentStatusOutput.sourcePath);
227
- console.log("Document path = " + documentStatusOutput.path);
228
- console.log("Target language = " + documentStatusOutput.to);
229
- console.log("Document created dateTime = " + documentStatusOutput.createdDateTimeUtc);
230
- console.log("Document last action date time = " + documentStatusOutput.lastActionDateTimeUtc);
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
- ```typescript
238
- console.log("== Get Translations Status ==");
239
- const client = createClient(endpoint, credentials);
240
-
241
- const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
242
- const sourceInput = createSourceInput(sourceUrl);
243
- const targetUrl = await createTargetContainer();
244
- const targetInput = createTargetInput(targetUrl, "fr");
245
- const batchRequest = createBatchRequest(sourceInput, [targetInput]);
246
-
247
- //Start translation
248
- const batchRequests = {inputs: [batchRequest]};
249
- const translationResponse = await StartTranslationAndWait(client, batchRequests);
250
- const operationLocationUrl = translationResponse.headers["operation-location"]
251
- const operationId = getTranslationOperationID(operationLocationUrl);
252
-
253
- //get Translation Statusby ID filter
254
- const queryParams = {
255
- ids: [operationId]
256
- };
257
- const response = await client.path("/document/batches").get({
258
- queryParameters: queryParams
259
- });
260
- if (isUnexpected(response)) {
261
- throw response.body;
262
- }
263
- const responseBody = response.body;
264
- for (const translationStatus of responseBody.value) {
265
- console.log("Translation ID = " + translationStatus.id);
266
- console.log("Translation Status = " + translationStatus.status);
267
- console.log("Translation createdDateTimeUtc = " + translationStatus.createdDateTimeUtc);
268
- console.log("Translation lastActionDateTimeUtc = " + translationStatus.lastActionDateTimeUtc);
269
- console.log("Total documents submitted for translation = " + translationStatus.summary.total);
270
- console.log("Total characters charged = " + translationStatus.summary.totalCharacterCharged);
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
- const sourceUrl = await createSourceContainer(ONE_TEST_DOCUMENTS);
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
- //Start translation
288
- const batchRequests = {inputs: [batchRequest]};
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 operationLocationUrl = translationResponse.headers["operation-location"]
292
- const operationId = getTranslationOperationID(operationLocationUrl);
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
- //get Translation Status
295
- const response = await client.path("/document/batches/{id}",operationId).get() as GetTranslationStatus200Response;
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
- throw response.body;
349
+ throw response.body.error;
298
350
  }
299
351
 
300
- console.log("Translation ID = " + response.body.id);
301
- console.log("Translation Status = " + response.body.status);
302
- console.log("Translation createdDateTimeUtc = " + response.body.createdDateTimeUtc);
303
- console.log("Translation lastActionDateTimeUtc = " + response.body.lastActionDateTimeUtc);
304
- console.log("Total documents submitted for translation = " + response.body.summary.total);
305
- console.log("Total characters charged = " + response.body.summary.totalCharacterCharged);
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
- ```typescript
314
- console.log("== List Supported Format Types ==");
365
+ ```ts snippet:ReadmeSampleGetSupportedFormats
366
+ import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
315
367
 
316
- const documentTranslationClient = DocumentTranslationClient(endpoint);
317
- const response = await documentTranslationClient.path("/document/formats").get();
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 fileFormatTypes = response.body;
320
- fileFormatTypes.value.forEach((fileFormatType: { format: any; contentTypes: any; fileExtensions: any; }) => {
321
- console.log(fileFormatType.format);
322
- console.log(fileFormatType.contentTypes);
323
- console.log(fileFormatType.fileExtensions);
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
- ```javascript
340
- const { setLogLevel } = require("@azure/logger");
399
+ ```ts snippet:SetLogLevel
400
+ import { setLogLevel } from "@azure/logger";
341
401
 
342
402
  setLogLevel("info");
343
403
  ```