From 3a42bffa856416bfcffe7cb1f78f2d91c40bd447 Mon Sep 17 00:00:00 2001 From: suuft Date: Wed, 21 Dec 2022 15:17:09 +0300 Subject: [PATCH] feat: auto translate --- README.md | 4 ++-- build.gradle | 2 +- .../net/suuft/libretranslate/Translator.java | 11 +++++------ .../libretranslate/type/TranslateRequest.java | 16 ---------------- src/test/java/net/suuft/libretranslate/Test.java | 2 +- 5 files changed, 9 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/net/suuft/libretranslate/type/TranslateRequest.java diff --git a/README.md b/README.md index 9c6563c..59a1d42 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ repositories { dependencies { // other depends - implementation 'net.clojars.suuft:libretranslate-java:1.0.1' + implementation 'net.clojars.suuft:libretranslate-java:1.0.2' } ``` @@ -38,7 +38,7 @@ Depend: net.clojars.suuft libretranslate-java - 1.0.1 + 1.0.2 ``` ### `Usage:` diff --git a/build.gradle b/build.gradle index 3130903..f178259 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'net.clojars.suuft' -version '1.0.1' +version '1.0.2' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } diff --git a/src/main/java/net/suuft/libretranslate/Translator.java b/src/main/java/net/suuft/libretranslate/Translator.java index 838e75a..a87e9ef 100644 --- a/src/main/java/net/suuft/libretranslate/Translator.java +++ b/src/main/java/net/suuft/libretranslate/Translator.java @@ -3,17 +3,11 @@ import lombok.NonNull; import lombok.Setter; import lombok.experimental.UtilityClass; -import net.suuft.libretranslate.type.TranslateRequest; import net.suuft.libretranslate.type.TranslateResponse; import net.suuft.libretranslate.util.JsonUtil; - -import javax.net.ssl.HttpsURLConnection; -import java.io.BufferedReader; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.*; -import java.nio.charset.StandardCharsets; import java.util.Scanner; @UtilityClass @@ -52,6 +46,11 @@ public String translate(@NonNull String from, @NonNull String to, @NonNull Strin e.printStackTrace(); return "Falled translate!"; } + + } + public String translate(@NonNull String to, @NonNull String request){ + return translate("auto", to, request); + } } diff --git a/src/main/java/net/suuft/libretranslate/type/TranslateRequest.java b/src/main/java/net/suuft/libretranslate/type/TranslateRequest.java deleted file mode 100644 index 4e7cfac..0000000 --- a/src/main/java/net/suuft/libretranslate/type/TranslateRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.suuft.libretranslate.type; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.experimental.FieldDefaults; - -@AllArgsConstructor -@FieldDefaults(level = AccessLevel.PRIVATE) -public class TranslateRequest { - - String q; - String source; - String target; - String format; //"text", -// String api_key; -} diff --git a/src/test/java/net/suuft/libretranslate/Test.java b/src/test/java/net/suuft/libretranslate/Test.java index 254eb22..debda51 100644 --- a/src/test/java/net/suuft/libretranslate/Test.java +++ b/src/test/java/net/suuft/libretranslate/Test.java @@ -3,6 +3,6 @@ public class Test { public static void main(String[] args) { Translator.setUrlApi("https://libretranslate.de/translate"); - System.out.println(Translator.translate("ru", "en", "Для примера, переведем текст с русского на английский и выведем в консоль:")); + System.out.println(Translator.translate("auto", "en", "Для примера, переведем текст с русского на английский и выведем в консоль:")); } }