|
| 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 | +} |
0 commit comments