66import com .translated .lara .net .HttpParams ;
77import com .translated .lara .net .LaraClient ;
88
9- import java .util .HashMap ;
10- import java .util .List ;
11- import java .util .Map ;
9+ import java .util .*;
1210
1311public class Translator {
1412
@@ -32,6 +30,58 @@ public List<String> getLanguages() throws LaraException {
3230 return client .get ("/languages" ).asList (String .class );
3331 }
3432
33+ public DetectResult detect (String text ) throws LaraException {
34+ return detectAny (text , null , null );
35+ }
36+ public DetectResult detect (String text , String hint ) throws LaraException {
37+ return detectAny (text , hint , null );
38+ }
39+ public DetectResult detect (String text , String hint , List <String > passlist ) throws LaraException {
40+ return detectAny (text , hint , passlist );
41+ }
42+ public DetectResult detect (String text , String hint , String [] passlist ) throws LaraException {
43+ return detectAny (text , hint , Arrays .asList (passlist ));
44+ }
45+
46+ public DetectResult detect (String [] text ) throws LaraException {
47+ return detectAny (text , null , null );
48+ }
49+ public DetectResult detect (String [] text , String hint ) throws LaraException {
50+ return detectAny (text , hint , null );
51+ }
52+ public DetectResult detect (String [] text , String hint , List <String > passlist ) throws LaraException {
53+ return detectAny (text , hint , passlist );
54+ }
55+ public DetectResult detect (String [] text , String hint , String [] passlist ) throws LaraException {
56+ return detectAny (text , hint , Arrays .asList (passlist ));
57+ }
58+
59+ public DetectResult detect (List <String > text ) throws LaraException {
60+ return detectAny (text , null , null );
61+ }
62+ public DetectResult detect (List <String > text , String hint ) throws LaraException {
63+ return detectAny (text , hint , null );
64+ }
65+ public DetectResult detect (List <String > text , String hint , List <String > passlist ) throws LaraException {
66+ return detectAny (text , hint , passlist );
67+ }
68+ public DetectResult detect (List <String > text , String hint , String [] passlist ) throws LaraException {
69+ return detectAny (text , hint , Arrays .asList (passlist ));
70+ }
71+
72+ public DetectResult detectAny (Object text , String hint , Collection <String > passlist ) throws LaraException {
73+ HttpParams <Object > params = new HttpParams <>();
74+ params .set ("q" , text );
75+ if (hint != null ) {
76+ params .set ("hint" , hint );
77+ }
78+ if (passlist != null && !passlist .isEmpty ()) {
79+ params .set ("passlist" , passlist );
80+ }
81+
82+ return client .post ("/detect" , params .build ()).as (DetectResult .class );
83+ }
84+
3585 public TextResult translate (String text , String source , String target ) throws LaraException {
3686 return translateAny (text , source , target , null );
3787 }
0 commit comments