Skip to content

Commit 32ce054

Browse files
hive-botclaude
andcommitted
revert: lower-case formality and splitSentences values again
The API rejects formality and split_sentences values that are not lower case, so sending them as given turned values such as 'Less' that worked before into HTTP 400 errors. Restore the lower-casing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a932605 commit 32ce054

5 files changed

Lines changed: 9 additions & 38 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
293293
`updateMultilingualGlossary()`, `updateMultilingualGlossaryDictionary()` and
294294
`replaceMultilingualGlossaryDictionary()`, so `' foo '` is sent as `'foo'` and
295295
a whitespace-only term throws a `DeepLError` before any request.
296-
- The `formality` option of text and document translation is sent as given,
297-
no longer lower-cased.
298-
- A `splitSentences` value other than the aliases `'on'`, `'default'` and
299-
`'off'` is sent as given, no longer lower-cased.
300296
- `getUsage()` leaves `character`, `document` and `teamDocument` undefined
301297
when the response's count or limit for them is not a number, as it already did
302298
for the API Pro usage fields. Before, a `null` or string value was returned as

‎README.md‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ console.log(await deeplClient.translateText('How are you?', null, 'de', { formal
176176
- `'nonewlines'`: input text will be split into sentences using punctuation
177177
but not newlines.
178178
- `'on'` and `'default'` are deprecated aliases of `'1'`.
179-
180-
The aliases `'on'`, `'default'` and `'off'` match in any letter case; any
181-
other value is sent exactly as given.
182179
- `preserveFormatting`: controls automatic-formatting-correction. Set to `true`
183180
to prevent automatic-correction of formatting, default: `false`.
184181
- `formality`: controls whether translations should lean toward informal or
@@ -191,8 +188,6 @@ console.log(await deeplClient.translateText('How are you?', null, 'de', { formal
191188
- `'default'`: use default formality.
192189
- `'prefer_less'`: use informal language if available, otherwise default.
193190
- `'prefer_more'`: use formal, more polite language if available, otherwise default.
194-
195-
The value is sent exactly as given, without changing its letter case.
196191
- `glossary`: specifies a glossary to use with translation, either as a string
197192
containing the glossary ID, or a `MultilingualGlossaryInfo`/`GlossaryInfo` as returned by
198193
`getMultilingualGlossary()`/`getGlossary()`.

‎src/types.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,14 @@ export interface TranslateTextOptions extends BaseRequestOptions {
184184
* for applications where each input translation text is only one sentence.
185185
* - 'nonewlines': Input translation text will be split into sentences using only punctuation
186186
* but not newlines.
187-
* The aliases 'on', 'default' and 'off' match in any letter case; any other value is sent as
188-
* given.
189187
*/
190188
splitSentences?: SentenceSplittingMode;
191189

192190
/** Set to true to prevent the translation engine from correcting some formatting aspects, and
193191
* instead leave the formatting unchanged, default is false. */
194192
preserveFormatting?: boolean;
195193

196-
/**
197-
* Controls whether translations should lean toward formal or informal language. Sent as given.
198-
*/
194+
/** Controls whether translations should lean toward formal or informal language. */
199195
formality?: Formality;
200196

201197
/** Specifies the ID of a glossary to use with translation. Or
@@ -281,9 +277,7 @@ export interface TranslateTextOptions extends BaseRequestOptions {
281277
* Options that can be specified when translating documents.
282278
*/
283279
export interface DocumentTranslateOptions extends BaseRequestOptions {
284-
/**
285-
* Controls whether translations should lean toward formal or informal language. Sent as given.
286-
*/
280+
/** Controls whether translations should lean toward formal or informal language. */
287281
formality?: Formality;
288282

289283
/** Specifies the ID of a glossary to use with translation. Or

‎src/utils.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ export function buildURLSearchParams(
249249
searchParams.append('source_lang', sourceLang);
250250
}
251251
if (formality !== undefined) {
252-
searchParams.append('formality', String(formality));
252+
const formalityStr = String(formality).toLowerCase();
253+
searchParams.append('formality', formalityStr);
253254
}
254255
if (glossary !== undefined) {
255256
if (!isString(glossary)) {
@@ -407,13 +408,13 @@ export function validateAndAppendTextOptions(
407408
return;
408409
}
409410
if (options.splitSentences !== undefined) {
410-
const alias = options.splitSentences.toLowerCase();
411-
if (alias === 'on' || alias === 'default') {
411+
const splitSentences = options.splitSentences.toLowerCase();
412+
if (splitSentences === 'on' || splitSentences === 'default') {
412413
data.append('split_sentences', '1');
413-
} else if (alias === 'off') {
414+
} else if (splitSentences === 'off') {
414415
data.append('split_sentences', '0');
415416
} else {
416-
data.append('split_sentences', options.splitSentences);
417+
data.append('split_sentences', splitSentences);
417418
}
418419
}
419420
if (options.preserveFormatting !== undefined) {

‎tests/offline/translateText.test.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('Translator.translateText', () => {
109109
['prefer_less', 'prefer_less'],
110110
['prefer_more', 'prefer_more'],
111111
['default', 'default'],
112+
['MORE', 'more'],
112113
])('sends formality %s as %s', async (formality, sent) => {
113114
expectTranslateBody({ ...baseBody, formality: sent });
114115

@@ -117,14 +118,6 @@ describe('Translator.translateText', () => {
117118
});
118119
});
119120

120-
it('sends formality as given, without lower-casing it', async () => {
121-
expectTranslateBody({ ...baseBody, formality: 'MORE' });
122-
123-
await makeTranslator().translateText('abc', null, 'de', {
124-
formality: <deepl.Formality>'MORE',
125-
});
126-
});
127-
128121
it.each([
129122
['on', '1'],
130123
['default', '1'],
@@ -141,14 +134,6 @@ describe('Translator.translateText', () => {
141134
});
142135
});
143136

144-
it('sends a splitSentences value other than an alias as given, without lower-casing it', async () => {
145-
expectTranslateBody({ ...baseBody, split_sentences: 'NoNewlines' });
146-
147-
await makeTranslator().translateText('abc', null, 'de', {
148-
splitSentences: <deepl.SentenceSplittingMode>'NoNewlines',
149-
});
150-
});
151-
152137
it('does not change the splitSentences value of the caller options', async () => {
153138
expectTranslateBody({ ...baseBody, split_sentences: '0' });
154139
const options: deepl.TranslateTextOptions = { splitSentences: 'OFF' };

0 commit comments

Comments
 (0)