Skip to content

Commit bbe6acd

Browse files
author
awstools
committed
feat(client-translate): Added support for calling TranslateDocument API.
1 parent 9330d73 commit bbe6acd

File tree

12 files changed

+1260
-827
lines changed

12 files changed

+1260
-827
lines changed

clients/client-translate/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ TagResource
322322

323323
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/classes/tagresourcecommand.html) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/interfaces/tagresourcecommandinput.html) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/interfaces/tagresourcecommandoutput.html)
324324

325+
</details>
326+
<details>
327+
<summary>
328+
TranslateDocument
329+
</summary>
330+
331+
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/classes/translatedocumentcommand.html) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/interfaces/translatedocumentcommandinput.html) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-translate/interfaces/translatedocumentcommandoutput.html)
332+
325333
</details>
326334
<details>
327335
<summary>

clients/client-translate/src/Translate.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ import {
7373
StopTextTranslationJobCommandOutput,
7474
} from "./commands/StopTextTranslationJobCommand";
7575
import { TagResourceCommand, TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
76+
import {
77+
TranslateDocumentCommand,
78+
TranslateDocumentCommandInput,
79+
TranslateDocumentCommandOutput,
80+
} from "./commands/TranslateDocumentCommand";
7681
import {
7782
TranslateTextCommand,
7883
TranslateTextCommandInput,
@@ -106,6 +111,7 @@ const commands = {
106111
StartTextTranslationJobCommand,
107112
StopTextTranslationJobCommand,
108113
TagResourceCommand,
114+
TranslateDocumentCommand,
109115
TranslateTextCommand,
110116
UntagResourceCommand,
111117
UpdateParallelDataCommand,
@@ -349,6 +355,23 @@ export interface Translate {
349355
cb: (err: any, data?: TagResourceCommandOutput) => void
350356
): void;
351357

358+
/**
359+
* @see {@link TranslateDocumentCommand}
360+
*/
361+
translateDocument(
362+
args: TranslateDocumentCommandInput,
363+
options?: __HttpHandlerOptions
364+
): Promise<TranslateDocumentCommandOutput>;
365+
translateDocument(
366+
args: TranslateDocumentCommandInput,
367+
cb: (err: any, data?: TranslateDocumentCommandOutput) => void
368+
): void;
369+
translateDocument(
370+
args: TranslateDocumentCommandInput,
371+
options: __HttpHandlerOptions,
372+
cb: (err: any, data?: TranslateDocumentCommandOutput) => void
373+
): void;
374+
352375
/**
353376
* @see {@link TranslateTextCommand}
354377
*/

clients/client-translate/src/TranslateClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
StopTextTranslationJobCommandOutput,
8282
} from "./commands/StopTextTranslationJobCommand";
8383
import { TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
84+
import { TranslateDocumentCommandInput, TranslateDocumentCommandOutput } from "./commands/TranslateDocumentCommand";
8485
import { TranslateTextCommandInput, TranslateTextCommandOutput } from "./commands/TranslateTextCommand";
8586
import { UntagResourceCommandInput, UntagResourceCommandOutput } from "./commands/UntagResourceCommand";
8687
import { UpdateParallelDataCommandInput, UpdateParallelDataCommandOutput } from "./commands/UpdateParallelDataCommand";
@@ -113,6 +114,7 @@ export type ServiceInputTypes =
113114
| StartTextTranslationJobCommandInput
114115
| StopTextTranslationJobCommandInput
115116
| TagResourceCommandInput
117+
| TranslateDocumentCommandInput
116118
| TranslateTextCommandInput
117119
| UntagResourceCommandInput
118120
| UpdateParallelDataCommandInput;
@@ -136,6 +138,7 @@ export type ServiceOutputTypes =
136138
| StartTextTranslationJobCommandOutput
137139
| StopTextTranslationJobCommandOutput
138140
| TagResourceCommandOutput
141+
| TranslateDocumentCommandOutput
139142
| TranslateTextCommandOutput
140143
| UntagResourceCommandOutput
141144
| UpdateParallelDataCommandOutput;

clients/client-translate/src/commands/StartTextTranslationJobCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export interface StartTextTranslationJobCommandOutput extends StartTextTranslati
118118
*
119119
* @throws {@link UnsupportedLanguagePairException} (client fault)
120120
* <p>Amazon Translate does not support translation from the language of the source text into the requested
121-
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/how-to-error-msg.html">Error messages</a>. </p>
121+
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
122122
*
123123
* @throws {@link TranslateServiceException}
124124
* <p>Base exception class for all service exceptions from Translate service.</p>
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// smithy-typescript generated code
2+
import { EndpointParameterInstructions, getEndpointPlugin } from "@aws-sdk/middleware-endpoint";
3+
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
4+
import { Command as $Command } from "@aws-sdk/smithy-client";
5+
import {
6+
FinalizeHandlerArguments,
7+
Handler,
8+
HandlerExecutionContext,
9+
HttpHandlerOptions as __HttpHandlerOptions,
10+
MetadataBearer as __MetadataBearer,
11+
MiddlewareStack,
12+
} from "@aws-sdk/types";
13+
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
14+
import { SerdeContext as __SerdeContext } from "@smithy/types";
15+
16+
import {
17+
TranslateDocumentRequest,
18+
TranslateDocumentRequestFilterSensitiveLog,
19+
TranslateDocumentResponse,
20+
TranslateDocumentResponseFilterSensitiveLog,
21+
} from "../models/models_0";
22+
import { de_TranslateDocumentCommand, se_TranslateDocumentCommand } from "../protocols/Aws_json1_1";
23+
import { ServiceInputTypes, ServiceOutputTypes, TranslateClientResolvedConfig } from "../TranslateClient";
24+
25+
/**
26+
* @public
27+
*/
28+
export { __MetadataBearer, $Command };
29+
/**
30+
* @public
31+
*
32+
* The input for {@link TranslateDocumentCommand}.
33+
*/
34+
export interface TranslateDocumentCommandInput extends TranslateDocumentRequest {}
35+
/**
36+
* @public
37+
*
38+
* The output of {@link TranslateDocumentCommand}.
39+
*/
40+
export interface TranslateDocumentCommandOutput extends TranslateDocumentResponse, __MetadataBearer {}
41+
42+
/**
43+
* @public
44+
* <p>Translates the input document from the source language to the target language.
45+
* This synchronous operation supports plain text or HTML for the input document.
46+
*
47+
* <code>TranslateDocument</code> supports translations from English to any supported language,
48+
* and from any supported language to English. Therefore, specify either the source language code
49+
* or the target language code as “en” (English).
50+
* </p>
51+
* <p>
52+
* <code>TranslateDocument</code> does not support language auto-detection. </p>
53+
* <p> If you set the <code>Formality</code> parameter, the request will fail if the target language does
54+
* not support formality. For a list of target languages that support formality, see
55+
* <a href="https://docs.aws.amazon.com/translate/latest/dg/customizing-translations-formality.html">Setting formality</a>.
56+
* </p>
57+
* @example
58+
* Use a bare-bones client and the command you need to make an API call.
59+
* ```javascript
60+
* import { TranslateClient, TranslateDocumentCommand } from "@aws-sdk/client-translate"; // ES Modules import
61+
* // const { TranslateClient, TranslateDocumentCommand } = require("@aws-sdk/client-translate"); // CommonJS import
62+
* const client = new TranslateClient(config);
63+
* const input = { // TranslateDocumentRequest
64+
* Document: { // Document
65+
* Content: "BLOB_VALUE", // required
66+
* ContentType: "STRING_VALUE", // required
67+
* },
68+
* TerminologyNames: [ // ResourceNameList
69+
* "STRING_VALUE",
70+
* ],
71+
* SourceLanguageCode: "STRING_VALUE", // required
72+
* TargetLanguageCode: "STRING_VALUE", // required
73+
* Settings: { // TranslationSettings
74+
* Formality: "FORMAL" || "INFORMAL",
75+
* Profanity: "MASK",
76+
* },
77+
* };
78+
* const command = new TranslateDocumentCommand(input);
79+
* const response = await client.send(command);
80+
* // { // TranslateDocumentResponse
81+
* // TranslatedDocument: { // TranslatedDocument
82+
* // Content: "BLOB_VALUE", // required
83+
* // },
84+
* // SourceLanguageCode: "STRING_VALUE", // required
85+
* // TargetLanguageCode: "STRING_VALUE", // required
86+
* // AppliedTerminologies: [ // AppliedTerminologyList
87+
* // { // AppliedTerminology
88+
* // Name: "STRING_VALUE",
89+
* // Terms: [ // TermList
90+
* // { // Term
91+
* // SourceText: "STRING_VALUE",
92+
* // TargetText: "STRING_VALUE",
93+
* // },
94+
* // ],
95+
* // },
96+
* // ],
97+
* // AppliedSettings: { // TranslationSettings
98+
* // Formality: "FORMAL" || "INFORMAL",
99+
* // Profanity: "MASK",
100+
* // },
101+
* // };
102+
*
103+
* ```
104+
*
105+
* @param TranslateDocumentCommandInput - {@link TranslateDocumentCommandInput}
106+
* @returns {@link TranslateDocumentCommandOutput}
107+
* @see {@link TranslateDocumentCommandInput} for command's `input` shape.
108+
* @see {@link TranslateDocumentCommandOutput} for command's `response` shape.
109+
* @see {@link TranslateClientResolvedConfig | config} for TranslateClient's `config` shape.
110+
*
111+
* @throws {@link InternalServerException} (server fault)
112+
* <p>An internal server error occurred. Retry your request.</p>
113+
*
114+
* @throws {@link InvalidRequestException} (client fault)
115+
* <p> The request that you made is not valid. Check your request to determine why it's not
116+
* valid and then retry the request. </p>
117+
*
118+
* @throws {@link LimitExceededException} (client fault)
119+
* <p>The specified limit has been exceeded. Review your request and retry it with a quantity
120+
* below the stated limit.</p>
121+
*
122+
* @throws {@link ResourceNotFoundException} (client fault)
123+
* <p>The resource you are looking for has not been found. Review the resource you're looking
124+
* for and see if a different resource will accomplish your needs before retrying the revised
125+
* request.</p>
126+
*
127+
* @throws {@link ServiceUnavailableException} (server fault)
128+
* <p>The Amazon Translate service is temporarily unavailable. Wait a bit and then retry your
129+
* request.</p>
130+
*
131+
* @throws {@link TooManyRequestsException} (client fault)
132+
* <p> You have made too many requests within a short period of time. Wait for a short time and
133+
* then try your request again.</p>
134+
*
135+
* @throws {@link UnsupportedLanguagePairException} (client fault)
136+
* <p>Amazon Translate does not support translation from the language of the source text into the requested
137+
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
138+
*
139+
* @throws {@link TranslateServiceException}
140+
* <p>Base exception class for all service exceptions from Translate service.</p>
141+
*
142+
*/
143+
export class TranslateDocumentCommand extends $Command<
144+
TranslateDocumentCommandInput,
145+
TranslateDocumentCommandOutput,
146+
TranslateClientResolvedConfig
147+
> {
148+
// Start section: command_properties
149+
// End section: command_properties
150+
151+
public static getEndpointParameterInstructions(): EndpointParameterInstructions {
152+
return {
153+
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
154+
Endpoint: { type: "builtInParams", name: "endpoint" },
155+
Region: { type: "builtInParams", name: "region" },
156+
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
157+
};
158+
}
159+
160+
/**
161+
* @public
162+
*/
163+
constructor(readonly input: TranslateDocumentCommandInput) {
164+
// Start section: command_constructor
165+
super();
166+
// End section: command_constructor
167+
}
168+
169+
/**
170+
* @internal
171+
*/
172+
resolveMiddleware(
173+
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
174+
configuration: TranslateClientResolvedConfig,
175+
options?: __HttpHandlerOptions
176+
): Handler<TranslateDocumentCommandInput, TranslateDocumentCommandOutput> {
177+
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
178+
this.middlewareStack.use(
179+
getEndpointPlugin(configuration, TranslateDocumentCommand.getEndpointParameterInstructions())
180+
);
181+
182+
const stack = clientStack.concat(this.middlewareStack);
183+
184+
const { logger } = configuration;
185+
const clientName = "TranslateClient";
186+
const commandName = "TranslateDocumentCommand";
187+
const handlerExecutionContext: HandlerExecutionContext = {
188+
logger,
189+
clientName,
190+
commandName,
191+
inputFilterSensitiveLog: TranslateDocumentRequestFilterSensitiveLog,
192+
outputFilterSensitiveLog: TranslateDocumentResponseFilterSensitiveLog,
193+
};
194+
const { requestHandler } = configuration;
195+
return stack.resolve(
196+
(request: FinalizeHandlerArguments<any>) =>
197+
requestHandler.handle(request.request as __HttpRequest, options || {}),
198+
handlerExecutionContext
199+
);
200+
}
201+
202+
/**
203+
* @internal
204+
*/
205+
private serialize(input: TranslateDocumentCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
206+
return se_TranslateDocumentCommand(input, context);
207+
}
208+
209+
/**
210+
* @internal
211+
*/
212+
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<TranslateDocumentCommandOutput> {
213+
return de_TranslateDocumentCommand(output, context);
214+
}
215+
216+
// Start section: command_body_extra
217+
// End section: command_body_extra
218+
}

clients/client-translate/src/commands/TranslateTextCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface TranslateTextCommandOutput extends TranslateTextResponse, __Met
119119
*
120120
* @throws {@link UnsupportedLanguagePairException} (client fault)
121121
* <p>Amazon Translate does not support translation from the language of the source text into the requested
122-
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/how-to-error-msg.html">Error messages</a>. </p>
122+
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
123123
*
124124
* @throws {@link TranslateServiceException}
125125
* <p>Base exception class for all service exceptions from Translate service.</p>

clients/client-translate/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from "./ListTextTranslationJobsCommand";
1414
export * from "./StartTextTranslationJobCommand";
1515
export * from "./StopTextTranslationJobCommand";
1616
export * from "./TagResourceCommand";
17+
export * from "./TranslateDocumentCommand";
1718
export * from "./TranslateTextCommand";
1819
export * from "./UntagResourceCommand";
1920
export * from "./UpdateParallelDataCommand";

clients/client-translate/src/endpoint/EndpointParameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const resolveClientEndpointParameters = <T>(
2525
};
2626

2727
export interface EndpointParameters extends __EndpointParameters {
28-
Region: string;
28+
Region?: string;
2929
UseDualStack?: boolean;
3030
UseFIPS?: boolean;
3131
Endpoint?: string;

clients/client-translate/src/endpoint/ruleset.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@ import { RuleSetObject } from "@aws-sdk/util-endpoints";
66
or see "smithy.rules#endpointRuleSet"
77
in codegen/sdk-codegen/aws-models/translate.json */
88

9-
const q="fn",
10-
r="argv",
11-
s="ref";
12-
const a=true,
13-
b=false,
14-
c="String",
15-
d="PartitionResult",
16-
e="tree",
17-
f="error",
18-
g="endpoint",
19-
h={"required":true,"default":false,"type":"Boolean"},
20-
i={[s]:"Endpoint"},
21-
j={[q]:"booleanEquals",[r]:[{[s]:"UseFIPS"},true]},
22-
k={[q]:"booleanEquals",[r]:[{[s]:"UseDualStack"},true]},
23-
l={},
24-
m={[q]:"booleanEquals",[r]:[true,{[q]:"getAttr",[r]:[{[s]:d},"supportsFIPS"]}]},
25-
n={[q]:"booleanEquals",[r]:[true,{[q]:"getAttr",[r]:[{[s]:d},"supportsDualStack"]}]},
9+
const q="required",
10+
r="fn",
11+
s="argv",
12+
t="ref";
13+
const a="isSet",
14+
b="tree",
15+
c="error",
16+
d="endpoint",
17+
e="PartitionResult",
18+
f={[q]:false,"type":"String"},
19+
g={[q]:true,"default":false,"type":"Boolean"},
20+
h={[t]:"Endpoint"},
21+
i={[r]:"booleanEquals",[s]:[{[t]:"UseFIPS"},true]},
22+
j={[r]:"booleanEquals",[s]:[{[t]:"UseDualStack"},true]},
23+
k={},
24+
l={[r]:"booleanEquals",[s]:[true,{[r]:"getAttr",[s]:[{[t]:e},"supportsFIPS"]}]},
25+
m={[r]:"booleanEquals",[s]:[true,{[r]:"getAttr",[s]:[{[t]:e},"supportsDualStack"]}]},
26+
n=[i],
2627
o=[j],
27-
p=[k];
28-
const _data={version:"1.0",parameters:{Region:{required:a,type:c},UseDualStack:h,UseFIPS:h,Endpoint:{required:b,type:c}},rules:[{conditions:[{[q]:"aws.partition",[r]:[{[s]:"Region"}],assign:d}],type:e,rules:[{conditions:[{[q]:"isSet",[r]:[i]}],type:e,rules:[{conditions:o,error:"Invalid Configuration: FIPS and custom endpoint are not supported",type:f},{type:e,rules:[{conditions:p,error:"Invalid Configuration: Dualstack and custom endpoint are not supported",type:f},{endpoint:{url:i,properties:l,headers:l},type:g}]}]},{conditions:[j,k],type:e,rules:[{conditions:[m,n],type:e,rules:[{endpoint:{url:"https://translate-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:l,headers:l},type:g}]},{error:"FIPS and DualStack are enabled, but this partition does not support one or both",type:f}]},{conditions:o,type:e,rules:[{conditions:[m],type:e,rules:[{type:e,rules:[{endpoint:{url:"https://translate-fips.{Region}.{PartitionResult#dnsSuffix}",properties:l,headers:l},type:g}]}]},{error:"FIPS is enabled but this partition does not support FIPS",type:f}]},{conditions:p,type:e,rules:[{conditions:[n],type:e,rules:[{endpoint:{url:"https://translate.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:l,headers:l},type:g}]},{error:"DualStack is enabled but this partition does not support DualStack",type:f}]},{endpoint:{url:"https://translate.{Region}.{PartitionResult#dnsSuffix}",properties:l,headers:l},type:g}]}]};
28+
p=[{[t]:"Region"}];
29+
const _data={version:"1.0",parameters:{Region:f,UseDualStack:g,UseFIPS:g,Endpoint:f},rules:[{conditions:[{[r]:a,[s]:[h]}],type:b,rules:[{conditions:n,error:"Invalid Configuration: FIPS and custom endpoint are not supported",type:c},{type:b,rules:[{conditions:o,error:"Invalid Configuration: Dualstack and custom endpoint are not supported",type:c},{endpoint:{url:h,properties:k,headers:k},type:d}]}]},{type:b,rules:[{conditions:[{[r]:a,[s]:p}],type:b,rules:[{conditions:[{[r]:"aws.partition",[s]:p,assign:e}],type:b,rules:[{conditions:[i,j],type:b,rules:[{conditions:[l,m],type:b,rules:[{type:b,rules:[{endpoint:{url:"https://translate-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:k,headers:k},type:d}]}]},{error:"FIPS and DualStack are enabled, but this partition does not support one or both",type:c}]},{conditions:n,type:b,rules:[{conditions:[l],type:b,rules:[{type:b,rules:[{endpoint:{url:"https://translate-fips.{Region}.{PartitionResult#dnsSuffix}",properties:k,headers:k},type:d}]}]},{error:"FIPS is enabled but this partition does not support FIPS",type:c}]},{conditions:o,type:b,rules:[{conditions:[m],type:b,rules:[{type:b,rules:[{endpoint:{url:"https://translate.{Region}.{PartitionResult#dualStackDnsSuffix}",properties:k,headers:k},type:d}]}]},{error:"DualStack is enabled but this partition does not support DualStack",type:c}]},{type:b,rules:[{endpoint:{url:"https://translate.{Region}.{PartitionResult#dnsSuffix}",properties:k,headers:k},type:d}]}]}]},{error:"Invalid Configuration: Missing Region",type:c}]}]};
2930
export const ruleSet: RuleSetObject = _data;

0 commit comments

Comments
 (0)