Skip to content

Commit d6c5b22

Browse files
committed
feat: Add Document Minification feature
1 parent cb453f1 commit d6c5b22

20 files changed

+1609
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [1.17.0] - 2025-02-25
88
### Added
9+
* Added document minification as a feature before document translation, to
10+
allow translation of large docx or pptx files. For more info check the README.
911
* Added .env.example file with `dotenv` library for environment variables management
1012
* Improve unit tests
11-
1213
### Changed
1314
* Upgrade cross-spawn library (see https://github.com/advisories/GHSA-3xgq-45jj-v275)
1415

@@ -283,7 +284,7 @@ client library took over this package name. Thanks to
283284
ownership.
284285

285286

286-
[Unreleased]: https://github.com/DeepLcom/deepl-node/compare/v1.16.0...HEAD
287+
[1.17.0]: https://github.com/DeepLcom/deepl-node/compare/v1.16.0...v1.17.0
287288
[1.16.0]: https://github.com/DeepLcom/deepl-node/compare/v1.15.0...v1.16.0
288289
[1.15.0]: https://github.com/DeepLcom/deepl-node/compare/v1.14.0...v1.15.0
289290
[1.14.0]: https://github.com/DeepLcom/deepl-node/compare/v1.13.1...v1.14.0

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DeepL's best-in-class translation technology.
1515
The DeepL Node.js library offers a convenient way for applications written for
1616
Node.js to interact with the DeepL API. We intend to support all API functions
1717
with the library, though support for new features may be added to the library
18-
after theyre added to the API.
18+
after they're added to the API.
1919

2020
## Getting an authentication key
2121

@@ -264,6 +264,64 @@ directly:
264264
- `filename`: if the input file is not provided as file path, this option is
265265
needed to specify the file extension.
266266
- `extraRequestParameters`: same as in [Text translation options](#text-translation-options).
267+
- `enableDocumentMinification`: A `bool` value. If set to `true`, the library will try to minify a document
268+
before translating it through the API, sending a smaller document if the file contains a lot of media. This is
269+
currently only supported for `pptx` and `docx` files. See also [Document minification](#document-minification).
270+
271+
#### Document minification
272+
In some contexts, one can end up with large document files (e.g. PowerPoint presentations
273+
or Word files with many contributors, especially in a larger organization). However, the
274+
DeepL API enforces a limit of 30 MB for most of these files (see Usage Limits in the docs).
275+
In the case that most of this size comes from media included in the documents (e.g. images,
276+
videos, animations), document minification can help.
277+
In this case, the library will create a temporary directory to extract the document into,
278+
replace the large media with tiny placeholders, create a minified document, translate that
279+
via the API, and re-insert the original media into the original file. Please note that this
280+
requires a bit of additional (temporary) disk space, we recommend at least 2x the file size
281+
of the document to be translated.
282+
283+
To use document minification, simply pass the option to the `translateDocument()` function:
284+
```typescript
285+
await translator.translateDocument(
286+
inFile, outFile, "en", "de", { enableDocumentMinification: true }
287+
);
288+
```
289+
In order to use document minification with the lower-level `uploadDocument()`,
290+
`isDocumentTranslationComplete()` and `downloadDocument()` methods as well as other details,
291+
see the `DocumentMinifier` class.
292+
293+
294+
Currently supported document types for minification:
295+
1. `pptx`
296+
2. `docx`
297+
298+
Currently supported media types for minification:
299+
1. `png`
300+
2. `jpg`
301+
3. `jpeg`
302+
4. `emf`
303+
5. `bmp`
304+
6. `tiff`
305+
7. `wdp`
306+
8. `svg`
307+
9. `gif`
308+
10. `mp4`
309+
11. `asf`
310+
12. `avi`
311+
13. `m4v`
312+
14. `mpg`
313+
15. `mpeg`
314+
16. `wmv`
315+
17. `mov`
316+
18. `aiff`
317+
19. `au`
318+
20. `mid`
319+
21. `midi`
320+
22. `mp3`
321+
23. `m4a`
322+
24. `wav`
323+
25. `wma`
324+
267325

268326
### Glossaries
269327

package-lock.json

Lines changed: 80 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
],
2121
"dependencies": {
2222
"@types/node": ">=12.0",
23+
"adm-zip": "^0.5.16",
2324
"axios": "^1.7.4",
2425
"dotenv": "^16.4.7",
2526
"form-data": "^3.0.0",
26-
"loglevel": ">=1.6.2"
27+
"loglevel": ">=1.6.2",
28+
"uuid": "^8.3.2"
2729
},
2830
"devDependencies": {
31+
"@types/adm-zip": "^0.5.7",
2932
"@types/jest": "^27.0.3",
33+
"@types/mock-fs": "^4.13.4",
3034
"@types/uuid": "^8.3.4",
3135
"@typescript-eslint/eslint-plugin": "^5.6.0",
3236
"@typescript-eslint/parser": "^5.6.0",
@@ -38,11 +42,11 @@
3842
"eslint-plugin-promise": "^6.0.0",
3943
"jest": "^27.4.3",
4044
"jest-junit": "^13.0.0",
45+
"mock-fs": "^5.5.0",
4146
"nock": "^13.3.0",
4247
"prettier": "^2.5.1",
4348
"ts-jest": "^27.1.1",
44-
"typescript": "^4.5.3",
45-
"uuid": "^8.3.2"
49+
"typescript": "^4.5.3"
4650
},
4751
"files": [
4852
"CHANGELOG.md",
@@ -62,6 +66,6 @@
6266
"format": "prettier --check .",
6367
"format:fix": "prettier --write .",
6468
"test": "jest",
65-
"test:coverage": "jest --coverage --reporters=\"default\" --reporters=\"jest-junit\""
69+
"test:coverage": "jest --coverage --reporters=\"default\" --reporters=\"jest-junit\" --maxWorkers=5"
6670
}
6771
}

0 commit comments

Comments
 (0)