/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.Translate;
using Amazon.Translate.Model;
namespace Amazon.PowerShell.Cmdlets.TRN
{
///
/// Translates input text from the source language to the target language. For a list
/// of available languages and language codes, see Supported
/// languages.
///
[Cmdlet("ConvertTo", "TRNTargetLanguage", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Translate.Model.TranslateTextResponse")]
[AWSCmdlet("Calls the Amazon Translate TranslateText API operation.", Operation = new[] {"TranslateText"}, SelectReturnType = typeof(Amazon.Translate.Model.TranslateTextResponse))]
[AWSCmdletOutput("Amazon.Translate.Model.TranslateTextResponse",
"This cmdlet returns an Amazon.Translate.Model.TranslateTextResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class ConvertToTRNTargetLanguageCmdlet : AmazonTranslateClientCmdlet, IExecutor
{
#region Parameter Settings_Formality
///
///
/// You can optionally specify the desired level of formality for translations to supported
/// target languages. The formality setting controls the level of formal language usage
/// (also known as register)
/// in the translation output. You can set the value to informal or formal. If you don't
/// specify a value for formality, or if the target language doesn't support formality,
/// the translation will ignore the formality setting. If you specify multiple target languages for the job, translate ignores the formality
/// setting for any unsupported target language.For a list of target languages that support formality, see Supported
/// languages in the Amazon Translate Developer Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Translate.Formality")]
public Amazon.Translate.Formality Settings_Formality { get; set; }
#endregion
#region Parameter Settings_Profanity
///
///
/// Enable the profanity setting if you want Amazon Translate to mask profane words and
/// phrases in your translation output.To mask profane words and phrases, Amazon Translate replaces them with the grawlix
/// string “?$#@$“. This 5-character sequence is used for each profane word or phrase,
/// regardless of the length or number of words.Amazon Translate doesn't detect profanity in all of its supported languages. For languages
/// that don't support profanity detection, see Unsupported
/// languages in the Amazon Translate Developer Guide.If you specify multiple target languages for the job, all the target languages must
/// support profanity masking. If any of the target languages don't support profanity
/// masking, the translation job won't mask profanity for any target language.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Translate.Profanity")]
public Amazon.Translate.Profanity Settings_Profanity { get; set; }
#endregion
#region Parameter SourceLanguageCode
///
///
/// The language code for the language of the source text. For a list of language codes,
/// see Supported
/// languages.To have Amazon Translate determine the source language of your text, you can specify
/// auto
in the SourceLanguageCode
field. If you specify auto
,
/// Amazon Translate will call Amazon
/// Comprehend to determine the source language.If you specify auto
, you must send the TranslateText
request
/// in a region that supports Amazon Comprehend. Otherwise, the request returns an error
/// indicating that autodetect is not supported.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String SourceLanguageCode { get; set; }
#endregion
#region Parameter TargetLanguageCode
///
///
/// The language code requested for the language of the target text. For a list of language
/// codes, see Supported
/// languages.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String TargetLanguageCode { get; set; }
#endregion
#region Parameter TerminologyName
///
///
/// The name of a terminology list file to add to the translation job. This file provides
/// source terms and the desired translation for each term. A terminology list can contain
/// a maximum of 256 terms. You can use one custom terminology resource in your translation
/// request.Use the ListTerminologies operation to get the available terminology lists.For more information about custom terminology lists, see Custom
/// terminology.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TerminologyNames")]
public System.String[] TerminologyName { get; set; }
#endregion
#region Parameter Text
///
///
/// The text to translate. The text string can be a maximum of 10,000 bytes long. Depending
/// on your character set, this may be fewer than 10,000 characters.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String Text { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Translate.Model.TranslateTextResponse).
/// Specifying the name of a property of type Amazon.Translate.Model.TranslateTextResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Text parameter.
/// The -PassThru parameter is deprecated, use -Select '^Text' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Text' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.TargetLanguageCode), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "ConvertTo-TRNTargetLanguage (TranslateText)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.Text;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Settings_Formality = this.Settings_Formality;
context.Settings_Profanity = this.Settings_Profanity;
context.SourceLanguageCode = this.SourceLanguageCode;
#if MODULAR
if (this.SourceLanguageCode == null && ParameterWasBound(nameof(this.SourceLanguageCode)))
{
WriteWarning("You are passing $null as a value for parameter SourceLanguageCode which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.TargetLanguageCode = this.TargetLanguageCode;
#if MODULAR
if (this.TargetLanguageCode == null && ParameterWasBound(nameof(this.TargetLanguageCode)))
{
WriteWarning("You are passing $null as a value for parameter TargetLanguageCode which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
if (this.TerminologyName != null)
{
context.TerminologyName = new List(this.TerminologyName);
}
context.Text = this.Text;
#if MODULAR
if (this.Text == null && ParameterWasBound(nameof(this.Text)))
{
WriteWarning("You are passing $null as a value for parameter Text which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.Translate.Model.TranslateTextRequest();
// populate Settings
var requestSettingsIsNull = true;
request.Settings = new Amazon.Translate.Model.TranslationSettings();
Amazon.Translate.Formality requestSettings_settings_Formality = null;
if (cmdletContext.Settings_Formality != null)
{
requestSettings_settings_Formality = cmdletContext.Settings_Formality;
}
if (requestSettings_settings_Formality != null)
{
request.Settings.Formality = requestSettings_settings_Formality;
requestSettingsIsNull = false;
}
Amazon.Translate.Profanity requestSettings_settings_Profanity = null;
if (cmdletContext.Settings_Profanity != null)
{
requestSettings_settings_Profanity = cmdletContext.Settings_Profanity;
}
if (requestSettings_settings_Profanity != null)
{
request.Settings.Profanity = requestSettings_settings_Profanity;
requestSettingsIsNull = false;
}
// determine if request.Settings should be set to null
if (requestSettingsIsNull)
{
request.Settings = null;
}
if (cmdletContext.SourceLanguageCode != null)
{
request.SourceLanguageCode = cmdletContext.SourceLanguageCode;
}
if (cmdletContext.TargetLanguageCode != null)
{
request.TargetLanguageCode = cmdletContext.TargetLanguageCode;
}
if (cmdletContext.TerminologyName != null)
{
request.TerminologyNames = cmdletContext.TerminologyName;
}
if (cmdletContext.Text != null)
{
request.Text = cmdletContext.Text;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.Translate.Model.TranslateTextResponse CallAWSServiceOperation(IAmazonTranslate client, Amazon.Translate.Model.TranslateTextRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Translate", "TranslateText");
try
{
#if DESKTOP
return client.TranslateText(request);
#elif CORECLR
return client.TranslateTextAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public Amazon.Translate.Formality Settings_Formality { get; set; }
public Amazon.Translate.Profanity Settings_Profanity { get; set; }
public System.String SourceLanguageCode { get; set; }
public System.String TargetLanguageCode { get; set; }
public List TerminologyName { get; set; }
public System.String Text { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}