forked from 5gi/DeepJ
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df7333becc | ||
|
|
15a75b88cc | ||
|
|
07c30ccf8e | ||
|
|
3af5d6da63 | ||
|
|
c135da4115 | ||
|
|
af64960abf | ||
|
|
f058a27be7 | ||
|
|
c0f3cb5e95 | ||
|
|
9781caea90 | ||
|
|
524a19dada | ||
|
|
4cceed428e | ||
|
|
dbf2af3c64 | ||
|
|
6f754483a5 | ||
|
|
fcb20efbd8 | ||
|
|
c1438bff2a | ||
|
|
b12e497afa |
48
README.md
48
README.md
@@ -2,54 +2,8 @@
|
||||
[](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/)
|
||||
[](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/)
|
||||
> Quick Setup
|
||||
<details><summary>Gradle</summary>
|
||||
<p>
|
||||
|
||||
Go to your build.gradle file and type:
|
||||
|
||||
```
|
||||
repositories {
|
||||
maven {
|
||||
url "https://git.nevets.tech/api/packages/5gi/maven"
|
||||
}
|
||||
}
|
||||
```
|
||||
and
|
||||
|
||||
```
|
||||
dependencies {
|
||||
implementation group: 'com.the5gi.deepj', name: 'DeepJ', version: 'VERSION'
|
||||
}
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details><summary>Maven</summary>
|
||||
<p>
|
||||
|
||||
Go to your pom.xml file and type:
|
||||
|
||||
```
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://git.nevets.tech/api/packages/5gi/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
and
|
||||
```
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.the5gi.deepj</groupId>
|
||||
<artifactId>DeepJ</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
There is none for no-bloat, build it yourself.
|
||||
> Info
|
||||
|
||||
[To see more details, see the wiki](https://git.nevets.tech/5gi/DeepJ/wiki/Home#user-content-usage-setup).
|
||||
|
||||
@@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
apply plugin: 'maven-publish'
|
||||
group 'com.the5gi.deepj'
|
||||
version '1.3.7'
|
||||
version '1.4.2'
|
||||
|
||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package com.the5gi.DeepJ;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import java.io.IOException;
|
||||
@@ -11,55 +10,33 @@ import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
public class Translator {
|
||||
public static String globalAuthKey = "null";
|
||||
protected Request request;
|
||||
public Translator() {
|
||||
if (globalAuthKey == null) {
|
||||
System.out.println("\n[DeepJ] You are currently using the Global Auth Key Translator Constructor." +"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
|
||||
public static String globalAPIKey = "null";
|
||||
public Translator(boolean silent) {
|
||||
if (globalAPIKey == null && !silent) {
|
||||
System.out.println("\n[DeepJ] You are currently using the Global API Key Translator Constructor." +"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
|
||||
} else {
|
||||
request = new Request(globalAuthKey);
|
||||
request = new Request(globalAPIKey);
|
||||
}
|
||||
}
|
||||
public Translator(String authKey) {
|
||||
if (!Objects.equals(globalAuthKey, "null")) {
|
||||
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)");
|
||||
public Translator(String apiKey, boolean silence) {
|
||||
if (!Objects.equals(globalAPIKey, "null") && !silence) {
|
||||
System.out.println("[DeepJ] Looks like you have defined a global API key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
|
||||
}
|
||||
request = new Request(authKey);
|
||||
request = new Request(apiKey);
|
||||
}
|
||||
public Translator(String authKey, boolean silence) {
|
||||
if (!Objects.equals(globalAuthKey, "null") && !silence) {
|
||||
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
|
||||
}
|
||||
request = new Request(authKey);
|
||||
public static void setGlobalAPIKey(String key) {
|
||||
globalAPIKey = key;
|
||||
}
|
||||
public static void setGlobalAuthKey(String key) {
|
||||
globalAuthKey = key;
|
||||
public static TranslatorBuilder newBuilder() {
|
||||
return new TranslatorBuilder();
|
||||
}
|
||||
public static Translator newTranslator(String authKey) {
|
||||
return new Translator(authKey);
|
||||
}
|
||||
public static Translator newTranslator() {
|
||||
if (globalAuthKey == null) {
|
||||
System.out.println("\n[DeepJ] You are currently using the Global Auth Key \".of()\" Translator." +
|
||||
"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this method." +
|
||||
"\n[DeepJ] If you want to define an different authkey every time do: \"Translator.of(String authKey)\"\n");
|
||||
return new Translator("null");
|
||||
} else {
|
||||
return new Translator();
|
||||
}
|
||||
}
|
||||
public void setAuthKey(String key) {
|
||||
public void setAPIKey(String key) {
|
||||
request.setAuthKey(key);
|
||||
}
|
||||
public void setAPIKey(String authKey) {
|
||||
request = new Request(authKey);
|
||||
}
|
||||
public String getAPIKey() {
|
||||
return request.authKey;
|
||||
}
|
||||
public void close() {
|
||||
request = new Request("null");
|
||||
}
|
||||
public String translate(Language langToTranslateTo, String sourceMessage) {
|
||||
if (request.authKey == "null") {
|
||||
System.out.println("[DeepJ] This translator is closed! Please re-create!");
|
||||
@@ -93,11 +70,41 @@ public class Translator {
|
||||
String encodedAuthKey = URLEncoder.encode(authKey, StandardCharsets.UTF_8);
|
||||
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder().GET().header("Accept","*/*").header("Content-Type", "application/x-www-form-urlencoded").uri(URI.create("https://api-free.deepl.com/v2/translate?auth_key="+encodedAuthKey+"&target_lang="+langEnum.getApiString()+"&text="+encodedMessage)).build();
|
||||
URI deepLURI = URI.create("https://api-free.deepl.com/v2/translate?auth_key="+encodedAuthKey+"&target_lang="+langEnum.getApiString()+"&text="+encodedMessage);
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.header("Accept","*/*")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.uri(deepLURI)
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString());
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
public static class TranslatorBuilder {
|
||||
private boolean silent = false;
|
||||
private String authKey = null;
|
||||
private boolean GAK = false;
|
||||
public Translator build() {
|
||||
if (GAK) {
|
||||
return new Translator(silent);
|
||||
} else {
|
||||
return new Translator(authKey, silent);
|
||||
}
|
||||
}
|
||||
public TranslatorBuilder useGAK(boolean bool) {
|
||||
this.GAK = bool;
|
||||
return this;
|
||||
}
|
||||
public TranslatorBuilder setAuthKey(String authKey) {
|
||||
this.authKey = authKey;
|
||||
return this;
|
||||
}
|
||||
public TranslatorBuilder setSilent(boolean silent) {
|
||||
this.silent = silent;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public enum Language {
|
||||
Bulgarian("BG"),
|
||||
Czech("CS"),
|
||||
@@ -133,4 +140,4 @@ public class Translator {
|
||||
return this.apiString;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user