Skip to content

Commit 236cbef

Browse files
authored
Add style to translate options
1 parent 9f989d2 commit 236cbef

6 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/main/java/com/translated/lara/translator/DocumentOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public class DocumentOptions {
66
private String[] adaptTo = null;
7+
private TranslationStyle style = null;
78

89
public String[] getAdaptTo() {
910
return adaptTo;
@@ -18,4 +19,13 @@ public DocumentOptions setAdaptTo(String... adaptTo) {
1819
this.adaptTo = adaptTo;
1920
return this;
2021
}
22+
23+
public TranslationStyle getStyle() {
24+
return style;
25+
}
26+
27+
public DocumentOptions setStyle(TranslationStyle style) {
28+
this.style = style;
29+
return this;
30+
}
2131
}

src/main/java/com/translated/lara/translator/DocumentTranslateOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class DocumentTranslateOptions {
1010
private String[] glossaries = null;
1111
private String outputFormat = null;
1212
private Boolean noTrace = null;
13+
private TranslationStyle style = null;
1314

1415
public String[] getAdaptTo() {
1516
return adaptTo;
@@ -57,11 +58,21 @@ public DocumentTranslateOptions setNoTrace(Boolean noTrace) {
5758
return this;
5859
}
5960

61+
public TranslationStyle getStyle() {
62+
return style;
63+
}
64+
65+
public DocumentTranslateOptions setStyle(TranslationStyle style) {
66+
this.style = style;
67+
return this;
68+
}
69+
6070
public HttpParams<Object> toParams() {
6171
HttpParams<Object> params = new HttpParams<>();
6272
params.set("adapt_to", adaptTo);
6373
params.set("glossaries", glossaries);
6474
params.set("output_format", outputFormat);
75+
params.set("style", TranslationStyle.toString(style));
6576

6677
return params;
6778
}

src/main/java/com/translated/lara/translator/DocumentUploadOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class DocumentUploadOptions {
99
private String[] adaptTo = null;
1010
private String[] glossaries = null;
1111
private Boolean noTrace = null;
12+
private TranslationStyle style = null;
1213

1314
public String[] getAdaptTo() {
1415
return adaptTo;
@@ -47,10 +48,20 @@ public DocumentUploadOptions setNoTrace(Boolean noTrace) {
4748
return this;
4849
}
4950

51+
public TranslationStyle getStyle() {
52+
return style;
53+
}
54+
55+
public DocumentUploadOptions setStyle(TranslationStyle style) {
56+
this.style = style;
57+
return this;
58+
}
59+
5060
public HttpParams<Object> toParams() {
5161
HttpParams<Object> params = new HttpParams<>();
5262
params.set("adapt_to", adaptTo);
5363
params.set("glossaries", glossaries);
64+
params.set("style", TranslationStyle.toString(style));
5465

5566
return params;
5667
}

src/main/java/com/translated/lara/translator/Documents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public InputStream translate(File input, String source, String target, DocumentT
119119
if (options != null && options.getAdaptTo() != null) uploadOptions.setAdaptTo(options.getAdaptTo());
120120
if (options != null && options.getGlossaries() != null) uploadOptions.setGlossaries(options.getGlossaries());
121121
if (options != null && options.getNoTrace()) uploadOptions.setNoTrace(true);
122+
if (options != null && options.getStyle() != null) uploadOptions.setStyle(options.getStyle());
122123

123124
Document document = upload(input, source, target, uploadOptions);
124125
document = pollDocumentUntilCompleted(document);

src/main/java/com/translated/lara/translator/TranslateOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum UseCache {
2828
private Integer cacheTTL = null;
2929
private Boolean noTrace = null;
3030
private Boolean verbose = null;
31+
private TranslationStyle style = null;
3132
private Map<String, String> headers = null;
3233

3334
public String getSourceHint() {
@@ -162,6 +163,15 @@ public TranslateOptions setHeaders(Map<String, String> headers) {
162163
return this;
163164
}
164165

166+
public TranslationStyle getStyle() {
167+
return style;
168+
}
169+
170+
public TranslateOptions setStyle(TranslationStyle style) {
171+
this.style = style;
172+
return this;
173+
}
174+
165175
public HttpParams<Object> toParams() {
166176
HttpParams<Object> params = new HttpParams<>();
167177
params.set("source_hint", sourceHint);
@@ -175,6 +185,7 @@ public HttpParams<Object> toParams() {
175185
params.set("use_cache", toString(useCache));
176186
params.set("cache_ttl", cacheTTL);
177187
params.set("verbose", verbose);
188+
params.set("style", TranslationStyle.toString(style));
178189

179190
return params;
180191
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.translated.lara.translator;
2+
3+
/**
4+
* Translation style constants
5+
*/
6+
public enum TranslationStyle {
7+
8+
FAITHFUL("faithful"),
9+
FLUID("fluid"),
10+
CREATIVE("creative");
11+
12+
private final String value;
13+
14+
TranslationStyle(String value) {
15+
this.value = value;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return value;
21+
}
22+
23+
public static String toString(TranslationStyle style) {
24+
return style != null ? style.toString() : null;
25+
}
26+
27+
}

0 commit comments

Comments
 (0)