Skip to content

Commit

Permalink
feat(client-translate): Added support for calling TranslateDocument API.
Browse files Browse the repository at this point in the history
  • Loading branch information
awstools committed May 23, 2023
1 parent 9330d73 commit bbe6acd
Show file tree
Hide file tree
Showing 12 changed files with 1,260 additions and 827 deletions.
8 changes: 8 additions & 0 deletions clients/client-translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ TagResource

[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)

</details>
<details>
<summary>
TranslateDocument
</summary>

[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)

</details>
<details>
<summary>
Expand Down
23 changes: 23 additions & 0 deletions clients/client-translate/src/Translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ import {
StopTextTranslationJobCommandOutput,
} from "./commands/StopTextTranslationJobCommand";
import { TagResourceCommand, TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
import {
TranslateDocumentCommand,
TranslateDocumentCommandInput,
TranslateDocumentCommandOutput,
} from "./commands/TranslateDocumentCommand";
import {
TranslateTextCommand,
TranslateTextCommandInput,
Expand Down Expand Up @@ -106,6 +111,7 @@ const commands = {
StartTextTranslationJobCommand,
StopTextTranslationJobCommand,
TagResourceCommand,
TranslateDocumentCommand,
TranslateTextCommand,
UntagResourceCommand,
UpdateParallelDataCommand,
Expand Down Expand Up @@ -349,6 +355,23 @@ export interface Translate {
cb: (err: any, data?: TagResourceCommandOutput) => void
): void;

/**
* @see {@link TranslateDocumentCommand}
*/
translateDocument(
args: TranslateDocumentCommandInput,
options?: __HttpHandlerOptions
): Promise<TranslateDocumentCommandOutput>;
translateDocument(
args: TranslateDocumentCommandInput,
cb: (err: any, data?: TranslateDocumentCommandOutput) => void
): void;
translateDocument(
args: TranslateDocumentCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: TranslateDocumentCommandOutput) => void
): void;

/**
* @see {@link TranslateTextCommand}
*/
Expand Down
3 changes: 3 additions & 0 deletions clients/client-translate/src/TranslateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
StopTextTranslationJobCommandOutput,
} from "./commands/StopTextTranslationJobCommand";
import { TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
import { TranslateDocumentCommandInput, TranslateDocumentCommandOutput } from "./commands/TranslateDocumentCommand";
import { TranslateTextCommandInput, TranslateTextCommandOutput } from "./commands/TranslateTextCommand";
import { UntagResourceCommandInput, UntagResourceCommandOutput } from "./commands/UntagResourceCommand";
import { UpdateParallelDataCommandInput, UpdateParallelDataCommandOutput } from "./commands/UpdateParallelDataCommand";
Expand Down Expand Up @@ -113,6 +114,7 @@ export type ServiceInputTypes =
| StartTextTranslationJobCommandInput
| StopTextTranslationJobCommandInput
| TagResourceCommandInput
| TranslateDocumentCommandInput
| TranslateTextCommandInput
| UntagResourceCommandInput
| UpdateParallelDataCommandInput;
Expand All @@ -136,6 +138,7 @@ export type ServiceOutputTypes =
| StartTextTranslationJobCommandOutput
| StopTextTranslationJobCommandOutput
| TagResourceCommandOutput
| TranslateDocumentCommandOutput
| TranslateTextCommandOutput
| UntagResourceCommandOutput
| UpdateParallelDataCommandOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface StartTextTranslationJobCommandOutput extends StartTextTranslati
*
* @throws {@link UnsupportedLanguagePairException} (client fault)
* <p>Amazon Translate does not support translation from the language of the source text into the requested
* 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>
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
*
* @throws {@link TranslateServiceException}
* <p>Base exception class for all service exceptions from Translate service.</p>
Expand Down
218 changes: 218 additions & 0 deletions clients/client-translate/src/commands/TranslateDocumentCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
// smithy-typescript generated code
import { EndpointParameterInstructions, getEndpointPlugin } from "@aws-sdk/middleware-endpoint";
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
} from "@aws-sdk/types";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
import { SerdeContext as __SerdeContext } from "@smithy/types";

import {
TranslateDocumentRequest,
TranslateDocumentRequestFilterSensitiveLog,
TranslateDocumentResponse,
TranslateDocumentResponseFilterSensitiveLog,
} from "../models/models_0";
import { de_TranslateDocumentCommand, se_TranslateDocumentCommand } from "../protocols/Aws_json1_1";
import { ServiceInputTypes, ServiceOutputTypes, TranslateClientResolvedConfig } from "../TranslateClient";

/**
* @public
*/
export { __MetadataBearer, $Command };
/**
* @public
*
* The input for {@link TranslateDocumentCommand}.
*/
export interface TranslateDocumentCommandInput extends TranslateDocumentRequest {}
/**
* @public
*
* The output of {@link TranslateDocumentCommand}.
*/
export interface TranslateDocumentCommandOutput extends TranslateDocumentResponse, __MetadataBearer {}

/**
* @public
* <p>Translates the input document from the source language to the target language.
* This synchronous operation supports plain text or HTML for the input document.
*
* <code>TranslateDocument</code> supports translations from English to any supported language,
* and from any supported language to English. Therefore, specify either the source language code
* or the target language code as “en” (English).
* </p>
* <p>
* <code>TranslateDocument</code> does not support language auto-detection. </p>
* <p> If you set the <code>Formality</code> parameter, the request will fail if the target language does
* not support formality. For a list of target languages that support formality, see
* <a href="https://docs.aws.amazon.com/translate/latest/dg/customizing-translations-formality.html">Setting formality</a>.
* </p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { TranslateClient, TranslateDocumentCommand } from "@aws-sdk/client-translate"; // ES Modules import
* // const { TranslateClient, TranslateDocumentCommand } = require("@aws-sdk/client-translate"); // CommonJS import
* const client = new TranslateClient(config);
* const input = { // TranslateDocumentRequest
* Document: { // Document
* Content: "BLOB_VALUE", // required
* ContentType: "STRING_VALUE", // required
* },
* TerminologyNames: [ // ResourceNameList
* "STRING_VALUE",
* ],
* SourceLanguageCode: "STRING_VALUE", // required
* TargetLanguageCode: "STRING_VALUE", // required
* Settings: { // TranslationSettings
* Formality: "FORMAL" || "INFORMAL",
* Profanity: "MASK",
* },
* };
* const command = new TranslateDocumentCommand(input);
* const response = await client.send(command);
* // { // TranslateDocumentResponse
* // TranslatedDocument: { // TranslatedDocument
* // Content: "BLOB_VALUE", // required
* // },
* // SourceLanguageCode: "STRING_VALUE", // required
* // TargetLanguageCode: "STRING_VALUE", // required
* // AppliedTerminologies: [ // AppliedTerminologyList
* // { // AppliedTerminology
* // Name: "STRING_VALUE",
* // Terms: [ // TermList
* // { // Term
* // SourceText: "STRING_VALUE",
* // TargetText: "STRING_VALUE",
* // },
* // ],
* // },
* // ],
* // AppliedSettings: { // TranslationSettings
* // Formality: "FORMAL" || "INFORMAL",
* // Profanity: "MASK",
* // },
* // };
*
* ```
*
* @param TranslateDocumentCommandInput - {@link TranslateDocumentCommandInput}
* @returns {@link TranslateDocumentCommandOutput}
* @see {@link TranslateDocumentCommandInput} for command's `input` shape.
* @see {@link TranslateDocumentCommandOutput} for command's `response` shape.
* @see {@link TranslateClientResolvedConfig | config} for TranslateClient's `config` shape.
*
* @throws {@link InternalServerException} (server fault)
* <p>An internal server error occurred. Retry your request.</p>
*
* @throws {@link InvalidRequestException} (client fault)
* <p> The request that you made is not valid. Check your request to determine why it's not
* valid and then retry the request. </p>
*
* @throws {@link LimitExceededException} (client fault)
* <p>The specified limit has been exceeded. Review your request and retry it with a quantity
* below the stated limit.</p>
*
* @throws {@link ResourceNotFoundException} (client fault)
* <p>The resource you are looking for has not been found. Review the resource you're looking
* for and see if a different resource will accomplish your needs before retrying the revised
* request.</p>
*
* @throws {@link ServiceUnavailableException} (server fault)
* <p>The Amazon Translate service is temporarily unavailable. Wait a bit and then retry your
* request.</p>
*
* @throws {@link TooManyRequestsException} (client fault)
* <p> You have made too many requests within a short period of time. Wait for a short time and
* then try your request again.</p>
*
* @throws {@link UnsupportedLanguagePairException} (client fault)
* <p>Amazon Translate does not support translation from the language of the source text into the requested
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
*
* @throws {@link TranslateServiceException}
* <p>Base exception class for all service exceptions from Translate service.</p>
*
*/
export class TranslateDocumentCommand extends $Command<
TranslateDocumentCommandInput,
TranslateDocumentCommandOutput,
TranslateClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

public static getEndpointParameterInstructions(): EndpointParameterInstructions {
return {
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
Endpoint: { type: "builtInParams", name: "endpoint" },
Region: { type: "builtInParams", name: "region" },
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
};
}

/**
* @public
*/
constructor(readonly input: TranslateDocumentCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: TranslateClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<TranslateDocumentCommandInput, TranslateDocumentCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.middlewareStack.use(
getEndpointPlugin(configuration, TranslateDocumentCommand.getEndpointParameterInstructions())
);

const stack = clientStack.concat(this.middlewareStack);

const { logger } = configuration;
const clientName = "TranslateClient";
const commandName = "TranslateDocumentCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: TranslateDocumentRequestFilterSensitiveLog,
outputFilterSensitiveLog: TranslateDocumentResponseFilterSensitiveLog,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

/**
* @internal
*/
private serialize(input: TranslateDocumentCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return se_TranslateDocumentCommand(input, context);
}

/**
* @internal
*/
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<TranslateDocumentCommandOutput> {
return de_TranslateDocumentCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface TranslateTextCommandOutput extends TranslateTextResponse, __Met
*
* @throws {@link UnsupportedLanguagePairException} (client fault)
* <p>Amazon Translate does not support translation from the language of the source text into the requested
* 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>
* target language. For more information, see <a href="https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html">Supported languages</a>. </p>
*
* @throws {@link TranslateServiceException}
* <p>Base exception class for all service exceptions from Translate service.</p>
Expand Down
1 change: 1 addition & 0 deletions clients/client-translate/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from "./ListTextTranslationJobsCommand";
export * from "./StartTextTranslationJobCommand";
export * from "./StopTextTranslationJobCommand";
export * from "./TagResourceCommand";
export * from "./TranslateDocumentCommand";
export * from "./TranslateTextCommand";
export * from "./UntagResourceCommand";
export * from "./UpdateParallelDataCommand";
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const resolveClientEndpointParameters = <T>(
};

export interface EndpointParameters extends __EndpointParameters {
Region: string;
Region?: string;
UseDualStack?: boolean;
UseFIPS?: boolean;
Endpoint?: string;
Expand Down
39 changes: 20 additions & 19 deletions clients/client-translate/src/endpoint/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import { RuleSetObject } from "@aws-sdk/util-endpoints";
or see "smithy.rules#endpointRuleSet"
in codegen/sdk-codegen/aws-models/translate.json */

const q="fn",
r="argv",
s="ref";
const a=true,
b=false,
c="String",
d="PartitionResult",
e="tree",
f="error",
g="endpoint",
h={"required":true,"default":false,"type":"Boolean"},
i={[s]:"Endpoint"},
j={[q]:"booleanEquals",[r]:[{[s]:"UseFIPS"},true]},
k={[q]:"booleanEquals",[r]:[{[s]:"UseDualStack"},true]},
l={},
m={[q]:"booleanEquals",[r]:[true,{[q]:"getAttr",[r]:[{[s]:d},"supportsFIPS"]}]},
n={[q]:"booleanEquals",[r]:[true,{[q]:"getAttr",[r]:[{[s]:d},"supportsDualStack"]}]},
const q="required",
r="fn",
s="argv",
t="ref";
const a="isSet",
b="tree",
c="error",
d="endpoint",
e="PartitionResult",
f={[q]:false,"type":"String"},
g={[q]:true,"default":false,"type":"Boolean"},
h={[t]:"Endpoint"},
i={[r]:"booleanEquals",[s]:[{[t]:"UseFIPS"},true]},
j={[r]:"booleanEquals",[s]:[{[t]:"UseDualStack"},true]},
k={},
l={[r]:"booleanEquals",[s]:[true,{[r]:"getAttr",[s]:[{[t]:e},"supportsFIPS"]}]},
m={[r]:"booleanEquals",[s]:[true,{[r]:"getAttr",[s]:[{[t]:e},"supportsDualStack"]}]},
n=[i],
o=[j],
p=[k];
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}]}]};
p=[{[t]:"Region"}];
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}]}]};
export const ruleSet: RuleSetObject = _data;
Loading

0 comments on commit bbe6acd

Please sign in to comment.