Official Java library for the DeepL language translation API.
Repo DeepL/deepl-java, read from GitHub 1 d ago. DeepL has not joined Take My Repo.
TL;DR: new APIs in this release: the Admin API, spoken terms, style profiles and text correction.
Translation memories, style rules and multilingual glossaries gained many options and fixes.
Read Changed and Deprecated before upgrading; no public API is removed in this release.
getStatusString() to TranslationMemoryJob andTranslationMemoryJobResult, returning the job status as the API sent it,TranslationMemoryJobResult.Status (for whichgetStatus() returns null).CreateTranslationMemoryImportOptions (content type, display name,createTranslationMemoryImport() overloads takingImportTranslationMemoryOptions (display name, content type, timeout,importTranslationMemoryFromFilepath() overloadsFile or with the file content as byte[] plus a fileexportTranslationMemoryToFilepath() overloads that write to anOutputStream, and one taking a TranslationMemoryInfo, a File and agetTranslationMemoryJob() and waitUntilTranslationMemoryJobDone()TranslationMemoryJob object.uploadTranslationMemoryFile(String uploadUrl, byte[] fileContent),application/xml.getStyleRule(), updateStyleRuleName(),deleteStyleRule(), updateStyleRuleConfiguredRules() and the four styleStyleRuleInfo object, andgetStyleRuleCustomInstruction(),updateStyleRuleCustomInstruction() and deleteStyleRuleCustomInstruction()CustomInstruction object.createStyleRule() and updateStyleRuleConfiguredRules() overloadsMap<String, Map<String, String>>, sentConfiguredRules canCreateStyleRuleOptions, UpdateStyleRuleNameOptions,UpdateStyleRuleConfiguredRulesOptions,CreateStyleRuleCustomInstructionOptions andUpdateStyleRuleCustomInstructionOptions, and overloads of the matching styleDeepLClient.updateMultilingualGlossary() andUpdateMultilingualGlossaryOptions, which rename a glossary and mergeCreateMultilingualGlossaryOptions andReplaceMultilingualGlossaryDictionaryOptions, and overloads of thegetMultilingualGlossary(), updateMultilingualGlossaryName(),updateMultilingualGlossaryDictionaryFromCsv() andreplaceMultilingualGlossaryDictionaryFromCsv() overloads that take aMultilingualGlossaryInfo object.DeepLException.getHttpStatusCode(), the HTTP status code of thenull if there was none), andDeepLException.getShouldRetry(), which is true for HTTP 429, HTTP 5xx andsetProxyUrl(String) to DeepLClientOptions (TranslatorOptions) andDeepLAdminClientOptions, which takes an HTTP proxy URL such ashttp://proxy.example.com:3128.TextTranslationOptions.setExtraBodyParameters() andDocumentTranslationOptions.setExtraBodyParameters() now return the optionssetStyleProfile() option to TextTranslationOptions andDocumentTranslationOptions, sent as style_profile_id on text andStyleProfileTagHandlingMode, TagHandlingVersion and ModelType enums andTextTranslationOptions.setTagHandling(), setTagHandlingVersion() andsetModelType() overloads that take them; the string setters remain.TextTranslationOptions.setFormality(String) andsetSentenceSplittingMode(String), which send the string as given, forFormality or SentenceSplittingMode.TextTranslationOptions.setSplittingTags(String),setNonSplittingTags(String) and setIgnoreTags(String), which send aTextTranslationOptions.setStyleRule(String) andsetTranslationMemory(String), taking the style rule or translation memoryTextTranslationOptions.setGlossaryIds(IGlossary, IGlossary...),Translator.translateDocumentGetStatus(), which returns the status oftranslateDocumentWaitUntilDone(DocumentHandle, Duration) overloadDeepLException when the timeout expires, andDocumentTranslationOptions.setTimeout(Duration), which limits how longtranslateDocument() waits for the translation; on expiry it throws aDocumentTranslationException with the document handle.DocumentTranslationOptions.setFilename(), the file name sent with theDocumentTranslationOptions.setFormality(String), which sends theDocumentTranslationOptions.setStyleRule(String),setTranslationMemory(String) andsetGlossaryIds(IGlossary, IGlossary...).DocumentStatus.getStatusString(), the status as the API sent it,DocumentStatus.StatusCode.TextResult.getTagHandlingVersion(), the tag handling version the APItag_handling_version); null when the response does not contain it.DeepLClient (/v3/style_profiles):createStyleProfile(), listStyleProfiles(), getStyleProfile(),updateStyleProfile() and deleteStyleProfile(), with the new classesStyleProfile, CreateStyleProfileOptions and UpdateStyleProfileOptionssetName()). Both options classes supportsetExtraBodyParameters(). setGlossaryIds(), setStyleRuleIds() andsetTranslationMemoryIds() take a list of IDs or the IGlossary,StyleRuleInfo or TranslationMemoryInfo objects. Options left null areStyleProfile.getCreationTime()getUpdatedTime() are never null; a response without a validcreation_time or updated_time raises a DeepLException.DeepLClient (/v3/spoken-terms):createSpokenTerms(), listSpokenTerms(), getSpokenTerms(),updateSpokenTerms(), getSpokenTermsEntries(), replaceSpokenTermsList(),deleteSpokenTerms() and deleteSpokenTermsList(), with the new classesSpokenTerms, SpokenTermsList and SpokenTermsEntries.updateSpokenTerms() takes an UpdateSpokenTermsOptions (setName(),setTermLists()) and sends only the fields set; createSpokenTerms() andreplaceSpokenTermsList() take optional CreateSpokenTermsOptions andReplaceSpokenTermsListOptions. All three options classes supportsetExtraBodyParameters(). Collection IDs are URL-encoded in the requestIllegalArgumentException.DeepLAdminClient class for the Admin API. It must be created withcreateDeveloperKey(), listDeveloperKeys(), deactivateDeveloperKey(),renameDeveloperKey(), setDeveloperKeyUsageLimits()) and retrieving usagegetUsageAnalytics() with an optional groupBy argument andgetCustomTagUsageAnalytics() with optional aggregateBy and pagegroupBy and aggregateBy take the AdminUsageGroupBy andCustomTagUsageAggregateBy enums or a string, sent as given; the client isDeepLAdminClientOptions). createDeveloperKey() takes aCreateDeveloperKeyOptions with the label; the other key functions haveDeactivateDeveloperKeyOptions,RenameDeveloperKeyOptions and SetDeveloperKeyUsageLimitsOptions. AllsetExtraBodyParameters(), added to the JSON body last.DeveloperKey, DeveloperKeyUsageLimits, AdminUsageReport,AdminUsageBreakdown (including getSpeechToSpeechMinutes()), KeyUsage,CustomTagUsageReport, CustomTagUsage and CustomTagUsageBreakdown.LocalDate, "YYYY-MM-DD" strings, or DateInstant values, of which the UTC day is sent; both the start and theDate values at midnight UTC.DeveloperKey.getLabel(), DeveloperKey.getUsageLimits(),KeyUsage.getApiKeyLabel(), AdminUsageReport.getTotalUsage() andAdminUsageBreakdown.getSpeechToSpeechMinutes() andCustomTagUsageBreakdown.getSpeechToSpeechMinutes() (both a Double) returnnull when the API sends no value.setDeveloperKeyUsageLimits() takes a DeveloperKeyUsageLimitsUpdate andGET /v2/usage to Usage:getApiKeyCharacter() (per-key character usage), getSpeechToTextMinutes(),getSpeechToSpeechMinutes(), getStartTime() and getEndTime() (billinggetProducts() (per-product usage as Usage.Product). They arenull when the response does not contain them, for example for Free accounts.DocumentTranslationOptions.setEnableWatermark() to add adocx and pdf documents.DocumentTranslationOptions.setOutputFormat() to request the filedocx. By default theLanguageCode constants for the target language variants de-CH,de-DE, es-ES, es-419, fr-CA, fr-FR, zh-Hans and zh-Hant. TheyLanguageCode constants.DeepLClient.getLanguagesForResource(), which callsGET /v3/languages for a given resource (translate_text, glossary,write, ...) and returns LanguageSupport objects with per-languageLanguageResourceName or a string;GetLanguagesForResourceOptions.setInclude() takesLanguageInclude values (Beta, External) or strings, each sent as aninclude query parameter.DeepLClient.getLanguageResources(), which callsGET /v3/languages/resources and returns LanguageResource objects[secure] when the API omits the flag).correctText() to the DeepLClient class, which corrects grammar, spelling/v2/write/correct endpoint. It accepts a singleCorrectTextOptions, which supports setExtraBodyParameters(). A responseDeepLException.TextRephraseOptions.setWritingStyle(WritingStyle) andsetTone(WritingTone) overloads; the string setters remain.TextRephraseOptions now extends BaseRequestOptions and supportssetExtraBodyParameters(), added last to the rephraseText() request body.null toDeepLClient.importTranslationMemoryFromFilepath(File, ...) as the secondsetFormality(), setStyleRule() orsetTranslationMemory() of TextTranslationOptions orDocumentTranslationOptions, to setTagHandling(),setTagHandlingVersion(), setSentenceSplittingMode(), setModelType(),setIgnoreTags(), setSplittingTags() or setNonSplittingTags() ofTextTranslationOptions, or to setWritingStyle() or setTone() ofTextRephraseOptions, fails to compile (reference to ... is ambiguous),null to the parameter(String) null. Already-compiled code is not affected.User-Agent as DeepL API requests (the one set with setHeaders(), if any);Authorization ortranslateText() sends the language codes with the language partzh-Hans; before, the part after the first - was upper-cased.setGlossary()) or glossary listsetGlossaryIds()) without a source language; the API detects the sourceTranslationMemoryJob.getProduct(), getOperation(), getCreationTime()getUpdatedTime() are no longer annotated @Nullable, as the API alwaysen and pt are now accepted in texten-US andpt-PT); previously they were rejected with an IllegalArgumentException.getSourceLanguages(), getTargetLanguages(), getLanguages() andgetGlossaryLanguages() now use GET /v3/languages instead of theen and pt as target languages.setApiVersion() no longer applies to these calls; previously a v1 settingmaxRetries, and ConnectionException.getShouldRetry()true for them; previously they failed at once. Developer keymaxRetries like timeouts, in all request types including PATCH;ConnectionException and is retried up to maxRetries; previouslyDeepLException and was not retried.GlossaryEntries now stores and sends terms trimmed of leading and trailingCharacter.isWhitespace()), so get(" foo ") no longer finds an" foo "; previously terms were stored as given. Target termsreplaceAll() or Map.Entry.setValue() are now checked, and anU+001F).translateDocumentWaitUntilDone() and translateDocument() keep polling andDocumentStatus.getStatus() returns null; previously they stopped withDeepLClientOptions setters now return DeepLClientOptions; previously theyTranslatorOptions, so DeepLClientOptions options = new DeepLClientOptions().setMaxRetries(1) did not compile and an inline setterDeepLClient(String, TranslatorOptions)AuthorizationException, like HTTP 403; previously aDeepLException with "Unknown error".DeepLException; previously aJsonSyntaxException, a NullPointerException, or null (for example fromgetUsage()).DeepLClient andTranslator constructors with an IllegalArgumentException; previously ittranslateDocumentDownload()) or translation memory exportdownloadTranslationMemoryExport()) is now retried up to maxRetries whilePATCH requests are now sent at most maxRetries + 1 times; previously eachmaxRetries.createDeveloperKey(), added in this release) iscreateStyleRule(String, String, ConfiguredRules, List) andupdateStyleRuleConfiguredRules(String, ConfiguredRules) are deprecated; useMap<String, Map<String, String>> instead.Translator.getLanguages(LanguageType) and the LanguageTypegetSourceLanguages() or getTargetLanguages() instead. TheyGlossaryNotFoundException. Catch its superclassNotFoundException instead, which is thrown for HTTP 404 on every endpoint.DeepLClientOptions.setApiVersion() and getApiVersion(); theLanguageCode (for exampleLanguageCode.German). Pass the language code as a string instead, for"de", or use getSourceLanguages() / getTargetLanguages().TextTranslationOptions.setGlossaryId(), setGlossaries(),setStyleId() and setTranslationMemoryId(). Use setGlossary(),setGlossaryIds(), setStyleRule() and setTranslationMemory() instead.Translator.translateDocumentStatus(); usetranslateDocumentGetStatus() instead. DeprecatedDocumentTranslationOptions.setGlossaryId(), setGlossaries(),setStyleId() and setTranslationMemoryId(); use setGlossary(),setGlossaryIds(), setStyleRule() and setTranslationMemory() instead.rephraseText() and correctText() send targetLang with only thezh-Hans is no longer sent as zh-HANS.{"error": {"message": "..."}} now puts itserror message: .translateDocumentDownload()) or translation memory exportdownloadTranslationMemoryExport()) now throws ConnectionExceptionIOException; IOException is left for failures writingUser-Agent header passed with setHeaders() now replaces the builtUser-Agent in any casing, e.g. user-agent.Authorization header passed with setHeaders() now replaces the builtAuthorization header in any casing, e.g. authorization; previously thegetMultilingualGlossaryDictionaryEntries()deleteMultilingualGlossaryDictionary() now encode a space as %20+.translateDocumentDownload() treats only 2xx responses as success; a 3xxDeepLExceptiontranslateDocumentDownload() maps an error response without body by itsQuotaExceededException orDocumentNotReadyException, instead of a plain DeepLException.exportTranslationMemoryToFilepath() with a File now checks the outputIOExceptionFileNotFoundException, the same classes as before.waitUntilTranslationMemoryJobDone() with a timeout, and the import andreplaceMultilingualGlossaryDictionary() andreplaceMultilingualGlossaryDictionaryFromCsv() now send a JSON body, thegetMultilingualGlossaryDictionaryEntries() now throws NotFoundExceptionGlossaryNotFoundException) if the response contains no dictionary andDeepLException if it is malformed, instead of anIndexOutOfBoundsException or NullPointerException.createMultilingualGlossary(), createMultilingualGlossaryFromCsv() andlistMultilingualGlossaries() now throw GlossaryNotFoundException on HTTPrephraseText() raises a DeepLException when the response does notIndexOutOfBoundsException or returned null, and thetranslateDocumentGetStatus() and translateDocumentDownload() nowtranslateDocumentUpload() and translateDocument() with an input stream/v2/document instead of /v2/document/.zh-Hans; it sentzh-HANS before.translateText() no longer fails when a translation in the response has nobilled_characters (getBilledCharacters() returns 0) or a nullmodel_type_used (getModelTypeUsed() returns null).LanguageCode.English andLanguageCode.Portuguese, which claimed they may only be used as sourcerephraseText() no longer throws a NullPointerException when the targetnull.getLanguages() no longer sends a POST request to /v2/languages; itGET.translateDocument() with file arguments and translateDocumentDownload()IOException.PATCH requests (updateMultilingualGlossaryName(),updateMultilingualGlossaryDictionary() and updateStyleRuleName()) now usehttp.proxyHost, https.proxyHost and others) likesetGlossaryIds()/setGlossaries() (up to 5 glossaries) inTextTranslationOptions and DocumentTranslationOptions.setStyleRule()/setStyleId() in DocumentTranslationOptions.setTranslationMemory()/setTranslationMemoryId()/setTranslationMemoryThreshold()DocumentTranslationOptions.DeepLClient class: getTranslationMemory(),listTranslationMemorySegments(), deleteTranslationMemory(),createTranslationMemoryImport(), uploadTranslationMemoryFile(),createTranslationMemoryExport(), getTranslationMemoryJob(),waitUntilTranslationMemoryJobDone(), downloadTranslationMemoryExport(),importTranslationMemoryFromFilepath() andexportTranslationMemoryToFilepath().creationTime and updatedTime to TranslationMemoryInfo.waitUntilTranslationMemoryJobDone(),importTranslationMemoryFromFilepath() andexportTranslationMemoryToFilepath().waitUntilTranslationMemoryJobDone() throwing when a translation memoryAwaitingInput. An import job keeps reporting that status for asetTranslationMemoryId() and setTranslationMemoryThreshold() inTextTranslationOptions.listTranslationMemories() method to the DeepLClient class forimage: registry.gitlab.com/gitlab-org/release-cli:latest.HttpContent and HttpClientWrapper, enablingsendJsonRequestWithBackoff() and sendJsonPatchRequestWithBackoff().DeepLClient class:createStyleRule(), getStyleRule(), updateStyleRuleName(),updateStyleRuleConfiguredRules(), and deleteStyleRule().DeepLClient class: createStyleRuleCustomInstruction(),getStyleRuleCustomInstruction(), updateStyleRuleCustomInstruction(),deleteStyleRuleCustomInstruction().setTagHandlingVersion() method to TextTranslationOptions to specify which version of the tag handling algorithm to use. Options are v1 and v2.setCustomInstructions() method to TextTranslationOptions to customize translation behavior with up to 10 instructions (max 300 characters each). Only supported for target languages: de, en, es, fr, it, ja, ko, zh and their variants. Note: using the custom instructions parameter will use quality_optimized model type as the default. Requests combining custom instructions and the latency_optimized model type will be rejected.