3
3
namespace AsyncAws \Translate \ValueObject ;
4
4
5
5
use AsyncAws \Core \Exception \InvalidArgument ;
6
+ use AsyncAws \Translate \Enum \Brevity ;
6
7
use AsyncAws \Translate \Enum \Formality ;
7
8
use AsyncAws \Translate \Enum \Profanity ;
8
9
9
10
/**
10
- * Settings to configure your translation output, including the option to set the formality level of the output text and
11
- * the option to mask profane words and phrases.
11
+ * Settings to configure your translation output. You can configure the following options:.
12
+ *
13
+ * - Brevity: reduces the length of the translation output for most translations. Available for `TranslateText` only.
14
+ * - Formality: sets the formality level of the translation output.
15
+ * - Profanity: masks profane words and phrases in the translation output.
12
16
*/
13
17
final class TranslationSettings
14
18
{
15
19
/**
16
- * You can optionally specify the desired level of formality for translations to supported target languages. The
17
- * formality setting controls the level of formal language usage (also known as register [^1]) in the translation
18
- * output. You can set the value to informal or formal. If you don't specify a value for formality, or if the target
19
- * language doesn't support formality, the translation will ignore the formality setting.
20
+ * You can specify the desired level of formality for translations to supported target languages. The formality setting
21
+ * controls the level of formal language usage (also known as register [^1]) in the translation output. You can set the
22
+ * value to informal or formal. If you don't specify a value for formality, or if the target language doesn't support
23
+ * formality, the translation will ignore the formality setting.
20
24
*
21
25
* If you specify multiple target languages for the job, translate ignores the formality setting for any unsupported
22
26
* target language.
@@ -32,8 +36,7 @@ final class TranslationSettings
32
36
private $ formality ;
33
37
34
38
/**
35
- * Enable the profanity setting if you want Amazon Translate to mask profane words and phrases in your translation
36
- * output.
39
+ * You can enable the profanity setting if you want to mask profane words and phrases in your translation output.
37
40
*
38
41
* To mask profane words and phrases, Amazon Translate replaces them with the grawlix string “?$#@$“. This
39
42
* 5-character sequence is used for each profane word or phrase, regardless of the length or number of words.
@@ -51,29 +54,55 @@ final class TranslationSettings
51
54
*/
52
55
private $ profanity ;
53
56
57
+ /**
58
+ * When you turn on brevity, Amazon Translate reduces the length of the translation output for most translations (when
59
+ * compared with the same translation with brevity turned off). By default, brevity is turned off.
60
+ *
61
+ * If you turn on brevity for a translation request with an unsupported language pair, the translation proceeds with the
62
+ * brevity setting turned off.
63
+ *
64
+ * For the language pairs that brevity supports, see Using brevity [^1] in the Amazon Translate Developer Guide.
65
+ *
66
+ * [^1]: https://docs.aws.amazon.com/translate/latest/dg/customizing-translations-brevity
67
+ *
68
+ * @var Brevity::*|null
69
+ */
70
+ private $ brevity ;
71
+
54
72
/**
55
73
* @param array{
56
74
* Formality?: null|Formality::*,
57
75
* Profanity?: null|Profanity::*,
76
+ * Brevity?: null|Brevity::*,
58
77
* } $input
59
78
*/
60
79
public function __construct (array $ input )
61
80
{
62
81
$ this ->formality = $ input ['Formality ' ] ?? null ;
63
82
$ this ->profanity = $ input ['Profanity ' ] ?? null ;
83
+ $ this ->brevity = $ input ['Brevity ' ] ?? null ;
64
84
}
65
85
66
86
/**
67
87
* @param array{
68
88
* Formality?: null|Formality::*,
69
89
* Profanity?: null|Profanity::*,
90
+ * Brevity?: null|Brevity::*,
70
91
* }|TranslationSettings $input
71
92
*/
72
93
public static function create ($ input ): self
73
94
{
74
95
return $ input instanceof self ? $ input : new self ($ input );
75
96
}
76
97
98
+ /**
99
+ * @return Brevity::*|null
100
+ */
101
+ public function getBrevity (): ?string
102
+ {
103
+ return $ this ->brevity ;
104
+ }
105
+
77
106
/**
78
107
* @return Formality::*|null
79
108
*/
@@ -108,6 +137,12 @@ public function requestBody(): array
108
137
}
109
138
$ payload ['Profanity ' ] = $ v ;
110
139
}
140
+ if (null !== $ v = $ this ->brevity ) {
141
+ if (!Brevity::exists ($ v )) {
142
+ throw new InvalidArgument (sprintf ('Invalid parameter "Brevity" for "%s". The value "%s" is not a valid "Brevity". ' , __CLASS__ , $ v ));
143
+ }
144
+ $ payload ['Brevity ' ] = $ v ;
145
+ }
111
146
112
147
return $ payload ;
113
148
}
0 commit comments