Skip to content

Commit 70fa21d

Browse files
hive-botclaude
andcommitted
feat: add updateMultilingualGlossary(), *FromCsv methods and glossary request options
Add updateMultilingualGlossary(glossary, options?) with UpdateMultilingualGlossaryOptions (name, dictionaries), sent as JSON with only the fields that are set. Add createMultilingualGlossaryFromCsv(), updateMultilingualGlossaryDictionaryFromCsv() and replaceMultilingualGlossaryDictionaryFromCsv(); the *WithCsv names are deprecated and delegate to them. The body-sending multilingual glossary methods take an optional last options argument with extraBodyParameters, added last to the body. getMultilingualGlossary() accepts a MultilingualGlossaryInfo as well as an ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b1fb355 commit 70fa21d

6 files changed

Lines changed: 434 additions & 103 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
126126
accept the label, prompt and optional source language as separate arguments:
127127
`createStyleRuleCustomInstruction(styleId, label, prompt, sourceLanguage?)` and
128128
`updateStyleRuleCustomInstruction(styleId, instructionId, label, prompt, sourceLanguage?)`.
129+
- Added `updateMultilingualGlossary(glossary, options?)`, which changes the
130+
name and merges dictionaries of a multilingual glossary in one request. The new
131+
`UpdateMultilingualGlossaryOptions` holds `name` and `dictionaries`; only the
132+
fields that are set are sent, as JSON.
133+
- Added `createMultilingualGlossaryFromCsv()`,
134+
`updateMultilingualGlossaryDictionaryFromCsv()` and
135+
`replaceMultilingualGlossaryDictionaryFromCsv()`, which replace the `*WithCsv()`
136+
methods of the same name and behave the same.
137+
- `createMultilingualGlossary()`, `createMultilingualGlossaryFromCsv()`,
138+
`updateMultilingualGlossaryName()`, `updateMultilingualGlossaryDictionary()`,
139+
`updateMultilingualGlossaryDictionaryFromCsv()`,
140+
`replaceMultilingualGlossaryDictionary()` and
141+
`replaceMultilingualGlossaryDictionaryFromCsv()` take an optional last
142+
`options` argument with `extraBodyParameters` (new types
143+
`CreateMultilingualGlossaryOptions` and
144+
`ReplaceMultilingualGlossaryDictionaryOptions`).
145+
- `getMultilingualGlossary()` accepts a `MultilingualGlossaryInfo` object as well
146+
as a glossary ID.
129147

130148
### Changed
131149
- `Formality`, `SentenceSplittingMode`, `TagHandlingMode`, `TagHandlingVersion`
@@ -200,6 +218,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
200218
`TranslationMemoryJobApiResponse` and `LanguageResourceApiResponse`) are
201219
deprecated. They are internal and will no longer be exported in the next
202220
major version.
221+
- `createMultilingualGlossaryWithCsv()`,
222+
`updateMultilingualGlossaryDictionaryWithCsv()` and
223+
`replaceMultilingualGlossaryDictionaryWithCsv()` are deprecated; use the
224+
`*FromCsv()` methods of the same name instead. They will be removed in the next
225+
major version.
203226

204227
### Fixed
205228
- `rephraseText()` and `correctText()` now throw `DeepLError` when the response

‎README.md‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ const glossaryEnToDe = await deeplClient.createMultilingualGlossary('My glossary
450450
```
451451

452452
You can also upload a glossary downloaded from the DeepL website using
453-
`createGlossaryWithCsv()`. Instead of supplying the entries as a dictionary,
453+
`createMultilingualGlossaryFromCsv()` (`createMultilingualGlossaryWithCsv()` is
454+
deprecated and behaves the same). Instead of supplying the entries as a dictionary,
454455
provide the CSV content as a string.
455456

456457
```javascript
@@ -464,7 +465,7 @@ try {
464465
throw error;
465466
}
466467
const csvContent = await readCsvFile(filePath);
467-
const glossaryEnToDe = await deeplClient.createMultilingualGlossaryWithCsv('My glossary', 'en', 'de', csvContent);
468+
const glossaryEnToDe = await deeplClient.createMultilingualGlossaryFromCsv('My glossary', 'en', 'de', csvContent);
468469
```
469470

470471
The [API documentation][api-docs-csv-format] explains the expected CSV format in
@@ -501,7 +502,8 @@ console.log(resultWithGlossary.text); // 'Der Maler wurde mit einem Gewinn ausge
501502

502503
Functions to get, list, and delete stored glossaries are also provided:
503504

504-
- `getMultilingualGlossary()` takes a glossary ID and returns a
505+
- `getMultilingualGlossary()` takes a glossary ID or `MultilingualGlossaryInfo`
506+
object and returns a
505507
`Promise<MultilingualGlossaryInfo>` object for a stored glossary, or raises an
506508
exception if no such glossary is found.
507509
- `listMultilingualGlossaries()` returns a promise of a list of `MultilingualGlossaryInfo` objects
@@ -548,6 +550,11 @@ console.log(entriesObj.entries.toTsv()); // 'hello\thallo'
548550

549551
Functions to edit stored glossaries are also provided:
550552

553+
- `updateMultilingualGlossary()` takes a glossary ID or `MultilingualGlossaryInfo`
554+
object and an optional `UpdateMultilingualGlossaryOptions` with `name` and
555+
`dictionaries`, and changes the name and merges the dictionaries in one request.
556+
Only the fields that are set are sent. The methods below are shortcuts for one
557+
field.
551558
- `updateMultilingualGlossaryDictionary()` takes a glossary ID or `MultilingualGlossaryInfo`
552559
object, plus a source language, target language, and a dictionary of entries.
553560
It will then either update the list of entries for that dictionary (either
@@ -560,12 +567,26 @@ Functions to edit stored glossaries are also provided:
560567
replacing any pre-existing entries for that language pair.
561568
- `updateMultilingualGlossaryName()` takes a glossary ID or `MultilingualGlossaryInfo`
562569
object, plus the new name of the glossary.
570+
- `updateMultilingualGlossaryDictionaryFromCsv()` and
571+
`replaceMultilingualGlossaryDictionaryFromCsv()` take a glossary ID or
572+
`MultilingualGlossaryInfo` object, a source language, target language and the
573+
entries as CSV content. The `*WithCsv()` methods of the same name are
574+
deprecated and behave the same.
575+
576+
Every method that takes a glossary accepts its ID or a `MultilingualGlossaryInfo`
577+
object. The methods that send a request body (`createMultilingualGlossary()`,
578+
`createMultilingualGlossaryFromCsv()`, `updateMultilingualGlossary()`, the
579+
`updateMultilingualGlossary*()` shortcuts and `replaceMultilingualGlossaryDictionary*()`)
580+
take an optional last `options` argument with `extraBodyParameters`: extra fields
581+
added last to the request body, replacing fields of the same name.
563582

564583
```javascript
565584
const glossaryDicts = [{sourceLangCode: 'en', targetLangCode: 'de', entries: new deepl.GlossaryEntries({ entries: {"artist": "Maler", "hello": "guten tag"} })}];
566585
const myGlossary = await deeplClient.createMultilingualGlossary('My Glossary', glossaryDicts);
567586
const newDict = {sourceLangCode: 'en', targetLangCode: 'de', entries: new deepl.GlossaryEntries({ entries: {"hello": "hallo", "prize": "Gewinn"} })};
568587
const updatedGlossary = await deeplClient.updateMultilingualGlossaryDictionary(myGlossary, newDict);
588+
// Rename the glossary and merge entries in one request
589+
await deeplClient.updateMultilingualGlossary(myGlossary, { name: 'My renamed glossary', dictionaries: [newDict] });
569590

570591
const entriesObj = await deeplClient.getMultilingualGlossaryDictionaryEntries(createdGlossary, 'en', 'de');
571592
console.log(entriesObj.entries.toTsv()); // {'artist': 'Maler', 'hello': 'hallo', 'prize': 'Gewinn'}

0 commit comments

Comments
 (0)