Skip to content

Commit 2bfe042

Browse files
Merge branch 'main' into dependabot/gradle/org.mockito-mockito-inline-5.2.0
2 parents 070ebc5 + b19aa1b commit 2bfe042

12 files changed

Lines changed: 272 additions & 18 deletions

File tree

.github/workflows/run_ci.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: '20 0 * * *'
10+
11+
env:
12+
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
13+
JAVA_TOOL_OPTIONS: ""
14+
SECRET_DETECTION_JSON_REPORT_FILE: "gitleaks.json"
15+
16+
jobs:
17+
spotless:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
- name: Spotless check
23+
run: ./gradlew spotlessCheck
24+
25+
license_check:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: License check
31+
run: |
32+
./license_checker.sh '*.java' | tee license_check_output.txt
33+
[ ! -s license_check_output.txt ]
34+
35+
secret_detection:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0
42+
- name: Install and run secret detection
43+
run: |
44+
wget https://github.com/gitleaks/gitleaks/releases/download/v8.18.4/gitleaks_8.18.4_linux_x64.tar.gz
45+
tar -xzf gitleaks_8.18.4_linux_x64.tar.gz
46+
EXITCODE=0
47+
./gitleaks detect -r ${SECRET_DETECTION_JSON_REPORT_FILE} --source . --log-opts="--all --full-history" || EXITCODE=$?
48+
if [[ $EXITCODE -ne 0 ]]; then
49+
exit $EXITCODE
50+
fi
51+
- name: Upload secret detection artifact
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: secret-detection-results
55+
path: gitleaks.json
56+
57+
58+
build:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
- name: Build
64+
run: ./gradlew assemble
65+
- name: Upload artifacts
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: build-artifacts
69+
path: deepl-java/build/
70+
71+
72+
73+
# Test and `gradlew publish` stage are disabled for now. Code needs to be tested
74+
75+
#######################################################
76+
# test_cl:
77+
# runs-on: ${{ matrix.docker-image }}
78+
# strategy:
79+
# matrix:
80+
# docker-image:
81+
# - 'eclipse-temurin:8-focal'
82+
# - 'openjdk:8-alpine'
83+
# - 'eclipse-temurin:11-alpine'
84+
# - 'eclipse-temurin:17-alpine'
85+
# - 'eclipse-temurin:18-alpine'
86+
# - 'eclipse-temurin:19-alpine'
87+
# use-mock-server:
88+
# - ''
89+
# - 'use mock server'
90+
# env:
91+
# DEEPL_SERVER_URL: http://deepl-mock:3000
92+
# DEEPL_MOCK_SERVER_PORT: 3000
93+
# DEEPL_PROXY_URL: http://deepl-mock:3001
94+
# DEEPL_MOCK_PROXY_SERVER_PORT: 3001
95+
# steps:
96+
# - name: Checkout
97+
# uses: actions/checkout@v4
98+
# - name: Start mock server
99+
# if: ${{ matrix.use-mock-server == 'use mock server' }}
100+
# run: docker run --name deepl-mock -d -p 3000:3000 deepl-mock
101+
# - name: Start mock proxy server
102+
# if: ${{ matrix.use-mock-server == 'use mock server' }}
103+
# run: docker run --name deepl-mock-proxy -d -p 3001:3001 deepl-mock-proxy
104+
# - name: Test
105+
# run: |
106+
# if [[ ! -z "${{ matrix.use-mock-server }}" ]]; then
107+
# echo "Using mock server"
108+
# export DEEPL_SERVER_URL=http://deepl-mock:3000
109+
# export DEEPL_MOCK_SERVER_PORT=3000
110+
# export DEEPL_PROXY_URL=http://deepl-mock:3001
111+
# export DEEPL_MOCK_PROXY_SERVER_PORT=3001
112+
# fi
113+
# ./gradlew test
114+
# - name: Stop mock proxy server
115+
# if: ${{ matrix.use-mock-server == 'use mock server' }}
116+
# run: docker stop deepl-mock-proxy
117+
# - name: Stop mock server
118+
# if: ${{ matrix.use-mock-server == 'use mock server' }}
119+
# run: docker stop deepl-mock
120+
# - name: Upload test results
121+
# uses: actions/upload-artifact@v4
122+
# with:
123+
# name: test-results
124+
# path: deepl-java/build/reports/tests/test
125+
126+
# test_examples:
127+
# runs-on: ${{ matrix.docker-image }}
128+
# strategy:
129+
# matrix:
130+
# docker-image:
131+
# - 'maven:3.9'
132+
# - 'maven:3.8-openjdk-18-slim'
133+
# - 'maven:3.8-openjdk-8-slim'
134+
# - 'maven:3.9-sapmachine-17'
135+
# - 'maven:3.9-eclipse-temurin-8'
136+
# - 'maven:3.9-eclipse-temurin-21'
137+
# steps:
138+
# - name: Checkout
139+
# uses: actions/checkout@v4
140+
# - name: Test examples
141+
# run: |
142+
# cd examples/maven/deepl-test-app
143+
# mvn install -B -PbuildProject -l mvn_build.log
144+
# mvn verify -PrunIntegrationTests
145+
# - name: Upload test results
146+
# uses: actions/upload-artifact@v4
147+
# with:
148+
# name: test-results
149+
# path: examples/maven/deepl-test-app/mvn_build.log
150+
151+
# publish:
152+
# runs-on: ubuntu-latest
153+
# needs: [ build ]
154+
# if: startsWith(github.ref, 'refs/tags/v')
155+
# steps:
156+
# - name: Checkout
157+
# uses: actions/checkout@v4
158+
# - name: Publish
159+
# run: ./gradlew publish

.gitlab-ci.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include:
1010
# Global --------------------------
1111

1212
# Use 17 (LTS) as base
13-
image: ${CI_REGISTRY_IMAGE}/eclipse-temurin:17-alpine
13+
image: eclipse-temurin:17-alpine
1414

1515
variables:
1616
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
@@ -103,6 +103,8 @@ build_manual:
103103
.test_base:
104104
stage: test
105105
extends: .test
106+
variables:
107+
KUBERNETES_MEMORY_LIMIT: 8Gi
106108
parallel:
107109
matrix:
108110
- DOCKER_IMAGE: "eclipse-temurin:18-alpine"
@@ -116,7 +118,7 @@ build_manual:
116118
USE_MOCK_SERVER: "use mock server"
117119
- DOCKER_IMAGE: "eclipse-temurin:19-alpine"
118120
USE_MOCK_SERVER: "use mock server"
119-
image: ${CI_REGISTRY_IMAGE}/${DOCKER_IMAGE}
121+
image: ${DOCKER_IMAGE}
120122
script:
121123
- >
122124
if [[ ! -z "${USE_MOCK_SERVER}" ]]; then
@@ -150,15 +152,17 @@ test_manual:
150152
.test_examples_base:
151153
stage: test
152154
extends: .test
155+
variables:
156+
MAVEN_OPTS: -Dmaven.repo.local=.m2/repository
153157
parallel:
154158
matrix:
155-
- DOCKER_IMAGE: "maven:3.8"
159+
- DOCKER_IMAGE: "maven:3.9"
156160
- DOCKER_IMAGE: "maven:3.8-openjdk-18-slim"
157161
- DOCKER_IMAGE: "maven:3.8-openjdk-8-slim"
158162
- DOCKER_IMAGE: "maven:3.9-sapmachine-17"
159-
- DOCKER_IMAGE: "maven:3.8-eclipse-temurin-8-focal"
160-
- DOCKER_IMAGE: "maven:3.8-eclipse-temurin-18-alpine"
161-
image: ${CI_REGISTRY_IMAGE}/${DOCKER_IMAGE}
163+
- DOCKER_IMAGE: "maven:3.9-eclipse-temurin-8"
164+
- DOCKER_IMAGE: "maven:3.9-eclipse-temurin-21"
165+
image: ${DOCKER_IMAGE}
162166
script:
163167
- cd examples/maven/deepl-test-app
164168
- mvn install -B -PbuildProject -l mvn_build.log
@@ -192,3 +196,14 @@ publish:
192196
script:
193197
- ./gradlew publish
194198

199+
publish_manual:
200+
stage: publish
201+
extends: .publish
202+
when: manual
203+
dependencies:
204+
- build_scheduled
205+
- build_manual
206+
rules:
207+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
208+
script:
209+
- ./gradlew publish

CHANGELOG.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ 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+
8+
## [1.5.0] - 2024-04-10
9+
### Added
10+
* New language available: Arabic (MSA) (`'ar'`). Add language code constants and tests.
11+
12+
Note: older library versions also support the new language, this update only
13+
adds new code constants.
14+
### Fixed
15+
* Change document upload to use the path `/v2/document` instead of `/v2/document/` (no trailing `/`).
16+
Both paths will continue to work in the v2 version of the API, but `/v2/document` is the intended one.
17+
18+
19+
## [1.4.0] - 2023-11-03
20+
### Added
21+
* Add optional `context` parameter for text translation, that specifies
22+
additional context to influence translations, that is not translated itself.
823
### Fixed
924
* Remove unused `commons-math` dependency
1025

@@ -89,7 +104,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
89104
Initial version.
90105

91106

92-
[Unreleased]: https://github.com/DeepLcom/deepl-java/compare/v1.3.0...HEAD
107+
[1.5.0]: https://github.com/DeepLcom/deepl-java/compare/v1.4.0...v1.5.0
108+
[1.4.0]: https://github.com/DeepLcom/deepl-java/compare/v1.3.0...v1.4.0
93109
[1.3.0]: https://github.com/DeepLcom/deepl-java/compare/v1.2.0...v1.3.0
94110
[1.2.0]: https://github.com/DeepLcom/deepl-java/compare/v1.1.0...v1.2.0
95111
[1.1.0]: https://github.com/DeepLcom/deepl-java/compare/v1.0.1...v1.1.0

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Java 1.8 or later.
3131
Add this dependency to your project's build file:
3232

3333
```
34-
implementation "com.deepl.api:deepl-java:1.3.0"
34+
implementation "com.deepl.api:deepl-java:1.5.0"
3535
```
3636

3737
### Maven users
@@ -42,7 +42,7 @@ Add this dependency to your project's POM:
4242
<dependency>
4343
<groupId>com.deepl.api</groupId>
4444
<artifactId>deepl-java</artifactId>
45-
<version>1.3.0</version>
45+
<version>1.5.0</version>
4646
</dependency>
4747
```
4848

@@ -159,6 +159,10 @@ a `TextTranslationOptions`, with the following setters:
159159
returned by glossary lookup functions, for example `listGlossaries()`).
160160
- `setGlossaryId()` is also available for backward-compatibility, accepting
161161
a string containing the glossary ID.
162+
- `setContext()`: specifies additional context to influence translations, that is not
163+
translated itself. Characters in the `context` parameter are not counted toward billing.
164+
See the [API documentation][api-docs-context-param] for more information and
165+
example usage.
162166
- `setTagHandling()`: type of tags to parse before translation, options are
163167
`"html"` and `"xml"`.
164168

@@ -623,6 +627,8 @@ tests using `./gradlew test` with the `DEEPL_MOCK_SERVER_PORT` and
623627

624628
[api-docs]: https://www.deepl.com/docs-api?utm_source=github&utm_medium=github-java-readme
625629

630+
[api-docs-context-param]: https://www.deepl.com/docs-api/translating-text/?utm_source=github&utm_medium=github-java-readme
631+
626632
[api-docs-csv-format]: https://www.deepl.com/docs-api/managing-glossaries/supported-glossary-formats/?utm_source=github&utm_medium=github-java-readme
627633

628634
[api-docs-xml-handling]: https://www.deepl.com/docs-api/handling-xml/?utm_source=github&utm_medium=github-java-readme

deepl-java/build.gradle.kts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "com.deepl.api"
9-
version = "1.3.0"
9+
version = "1.5.0"
1010

1111
val sharedManifest = the<JavaPluginConvention>().manifest {
1212
attributes (
@@ -25,11 +25,10 @@ repositories {
2525

2626
dependencies {
2727
implementation("org.jetbrains:annotations:20.1.0")
28-
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
28+
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
2929
testImplementation("org.mockito:mockito-inline:5.2.0")
30-
3130
// implementation("com.google.guava:guava:30.1.1-jre")
32-
implementation("com.google.code.gson:gson:2.9.0")
31+
implementation("com.google.code.gson:gson:2.10.1")
3332
}
3433

3534

deepl-java/src/main/java/com/deepl/api/LanguageCode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* Translator#getSourceLanguages()} and {@link Translator#getTargetLanguages()}.
1212
*/
1313
public class LanguageCode {
14+
/** Arabic (MSA) language code, may be used as source or target language */
15+
public static final String Arabic = "ar";
16+
1417
/** Bulgarian language code, may be used as source or target language. */
1518
public static final String Bulgarian = "bg";
1619

deepl-java/src/main/java/com/deepl/api/TextTranslationOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class TextTranslationOptions {
1818
private String glossaryId;
1919
private SentenceSplittingMode sentenceSplittingMode;
2020
private boolean preserveFormatting = false;
21+
private String context;
2122
private String tagHandling;
2223
private boolean outlineDetection = true;
2324
private Iterable<String> ignoreTags;
@@ -63,6 +64,16 @@ public TextTranslationOptions setGlossary(String glossaryId) {
6364
return this;
6465
}
6566

67+
/**
68+
* Specifies additional context to influence translations, that is not translated itself.
69+
* Characters in the `context` parameter are not counted toward billing. See the API documentation
70+
* for more information and example usage.
71+
*/
72+
public TextTranslationOptions setContext(String context) {
73+
this.context = context;
74+
return this;
75+
}
76+
6677
/**
6778
* Specifies how input translation text should be split into sentences. By default, this value is
6879
* <code>null</code> and the default sentence splitting mode is used.
@@ -151,6 +162,11 @@ public boolean isPreserveFormatting() {
151162
return preserveFormatting;
152163
}
153164

165+
/** Gets the current context. */
166+
public String getContext() {
167+
return context;
168+
}
169+
154170
/** Gets the current tag handling setting. */
155171
public String getTagHandling() {
156172
return tagHandling;

deepl-java/src/main/java/com/deepl/api/Translator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Translator(String authKey) throws IllegalArgumentException {
8282
*/
8383
private String constructUserAgentString(boolean sendPlatformInfo, AppInfo appInfo) {
8484
StringBuilder sb = new StringBuilder();
85-
sb.append("deepl-java/1.3.0");
85+
sb.append("deepl-java/1.5.0");
8686
if (sendPlatformInfo) {
8787
sb.append(" (");
8888
Properties props = System.getProperties();
@@ -447,7 +447,7 @@ public DocumentHandle translateDocumentUpload(
447447
try (FileInputStream inputStream = new FileInputStream(inputFile)) {
448448
HttpResponse response =
449449
httpClientWrapper.uploadWithBackoff(
450-
"/v2/document/", params, inputFile.getName(), inputStream);
450+
"/v2/document", params, inputFile.getName(), inputStream);
451451
checkResponse(response, false, false);
452452
return jsonParser.parseDocumentHandle(response.getBody());
453453
}
@@ -803,6 +803,9 @@ private static ArrayList<KeyValuePair<String, String>> createHttpParams(
803803
if (options.isPreserveFormatting()) {
804804
params.add(new KeyValuePair<>("preserve_formatting", "1"));
805805
}
806+
if (options.getContext() != null) {
807+
params.add(new KeyValuePair<>("context", options.getContext()));
808+
}
806809
if (options.getTagHandling() != null) {
807810
params.add(new KeyValuePair<>("tag_handling", options.getTagHandling()));
808811
}

0 commit comments

Comments
 (0)