38 Commits

Author SHA1 Message Date
5gi
df7333becc Update 'README.md' 2023-03-24 09:17:26 -04:00
5gi
15a75b88cc Removed Bloat
Signed-off-by: 5gi <5gi@5servers.us>
2023-03-24 09:15:03 -04:00
5gi
07c30ccf8e I'm Bored so I made a Builder #6 2023-03-23 10:21:28 -04:00
5gi
3af5d6da63 I'm Bored so I made a Builder #5 2023-03-23 10:19:24 -04:00
5gi
c135da4115 I'm Bored so I made a Builder #4 2023-03-23 10:16:07 -04:00
5gi
af64960abf I'm Bored so I made a Builder # 3 2023-03-23 10:13:51 -04:00
5gi
f058a27be7 I'm Bored so I made a Builder #2 2023-03-23 10:11:44 -04:00
5gi
c0f3cb5e95 I'm Bored so I made a Builder 2023-03-23 10:11:04 -04:00
5gi
9781caea90 Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-08 12:44:10 -05:00
5gi
524a19dada Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-08 12:43:26 -05:00
5gi
4cceed428e Update 'build.gradle' 2022-12-08 12:42:09 -05:00
5gi
dbf2af3c64 Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-08 12:40:56 -05:00
5gi
6f754483a5 Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-07 12:37:00 -05:00
5gi
fcb20efbd8 Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-07 12:36:11 -05:00
5gi
c1438bff2a Update 'build.gradle' 2022-12-07 11:18:54 -05:00
5gi
b12e497afa Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-12-07 11:17:24 -05:00
5gi
d8606a0587 Update 'README.md' 2022-11-18 20:07:21 -05:00
5gi
0aa351bebd Update 'README.md' 2022-11-18 18:08:17 -05:00
5gi
0f1fab61f8 Update 'README.md' 2022-11-18 18:04:49 -05:00
5gi
deae28702d fix version jenkins mb 2022-11-18 17:01:59 -05:00
5gi
92bc6ae4c7 trying api push hold on 2022-11-18 16:50:31 -05:00
5gi
bb1aaf7cee update version 2022-11-18 12:42:17 -05:00
5gi
e1017d8311 changed "Translaotr.of()" to "Translator.newTranslator()" 2022-11-18 12:41:11 -05:00
5gi
aab9802e56 Changed version. 2022-11-17 11:02:52 -05:00
5gi
15368ab222 Added ".close()" to Translator
closes Translator and Request
2022-11-17 11:01:24 -05:00
5gi
fab65fde3a Update 'build.gradle' 2022-11-17 07:20:22 -05:00
5gi
b3b37d0ac5 AHHHHHHHHHHHHHHHHHHHHHHHHHHH 2022-11-16 11:14:39 -05:00
5gi
ac4ce2192f fixed supposed to be comments because git sdtun 2022-11-16 11:12:21 -05:00
5gi
3345009f64 stupid comments removed 2022-11-16 11:09:57 -05:00
5gi
b72a411859 removed stupid comments 2022-11-16 11:09:15 -05:00
5gi
8a599d51f7 Update 'build.gradle' 2022-11-16 10:50:33 -05:00
5gi
6e31919236 Update 'build.gradle' 2022-11-16 10:49:41 -05:00
5gi
cf6d1e7128 fixed return and .setAuthKey again 2022-11-16 10:49:17 -05:00
5gi
dba816a33e prev commit 2022-11-16 09:45:46 -05:00
5gi
a31d12bbb5 added ".of()" to translator
added ".of()" to Translator.java so you don't have to type "new" so many times
added null protection to request
added ability to set authKey to requests
2022-11-16 09:45:20 -05:00
5gi
29442d1f9a Update 'build.gradle' 2022-11-16 07:41:24 -05:00
5gi
117b59d5e7 update readme i hate jenkins auto build sometimes 2022-11-15 10:59:39 -05:00
5gi
08b7665518 Update 'README.md' 2022-11-15 10:58:17 -05:00
4 changed files with 61 additions and 97 deletions

View File

@@ -16,11 +16,6 @@
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />

View File

@@ -1,53 +1,9 @@
# DeepJ
[![Build Number](https://api.5servers.us/get/badges?uniqueid=deepj&get-type=version.badge)](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/)
[![Build Status](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/badge/icon)](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).

View File

@@ -5,7 +5,7 @@ plugins {
}
apply plugin: 'maven-publish'
group 'com.the5gi.deepj'
version '1.2.9'
version '1.4.2'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11

View File

@@ -1,5 +1,4 @@
package com.the5gi.DeepJ;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
@@ -11,54 +10,38 @@ import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class Translator {
public static String globalAuthKey = "null";
public static void setGlobalAuthKey(String key) {
globalAuthKey = key;
}
private Request request;
public Translator() {
if (globalAuthKey == null) {
/*
[DeepJ] You are currently using the Global Auth Key Translator Constructor.
[DeepJ] If you are trying to use global auth keys, Call the method "Translator.setGlobalAuthKey(String key)" and then re-use this contructor.
[DeepJ] If you want to define a different authkey every time do: "new Translator(String authKey)"
*/
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");
protected Request request;
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")) {
/*
[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing "new Traslator()"
instead of "new Translator(String authKey)". NOTE: This will work but just some advice :)
*/
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) {
/*
[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing "new Traslator()"
instead of "new Translator(String authKey)". NOTE: This will work but just some advice :)
*/
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 void setAPIKey(String authKey) {
request = new Request(authKey);
public static TranslatorBuilder newBuilder() {
return new TranslatorBuilder();
}
public void setAPIKey(String key) {
request.setAuthKey(key);
}
public String getAPIKey() {
return request.authKey;
}
public String translate(Language langToTranslateTo, String sourceMessage) {
if (request.authKey == "null") {
System.out.println("[DeepJ] This translator is closed! Please re-create!");
return "null";
}
String response = "Error processing request";
try {
response = request.queryAPI(langToTranslateTo, sourceMessage);
@@ -76,22 +59,52 @@ instead of "new Translator(String authKey)". NOTE: This will work but just some
return message;
}
protected static class Request {
public final String authKey;
public String authKey;
public Request(String authKey) {
this.authKey = authKey;
}
public void setAuthKey(String key) {
authKey = key;
}
public String queryAPI(Language langEnum, String message) throws IOException, InterruptedException {
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();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
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"),