Compare commits

...

42 Commits

Author SHA1 Message Date
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
5gi
7d5efc7b00 testing jenkins 2022-11-15 10:29:40 -05:00
5gi
5d78663c87 added getAPIKey() to Translator.java 2022-11-15 10:19:44 -05:00
5gi
f47c69715c added getAPIKey() to Translator.java 2022-11-15 10:19:10 -05:00
5gi
732fc3882d Added ability to change authKey with a void 2022-11-15 10:16:18 -05:00
5gi
0e35a2f4c8 Update 'src/main/java/com/the5gi/DeepJ/Translator.java' 2022-11-15 10:15:34 -05:00
5gi
c00f4b1a2d Update 'README.md' 2022-11-10 11:13:56 -05:00
5gi
4c84fd5a98 update version 2022-11-09 15:11:50 -05:00
5gi
cc5a1b9df6 Update 'build.gradle' 2022-11-09 10:56:44 -05:00
5gi
787664bb38 Updated Main Class to remove unnecessary space 2022-11-09 10:55:16 -05:00
5gi
d1419d48e0 add 2022-11-09 07:00:05 -05:00
5gi
27cd9ec212 comment add 2022-11-08 19:02:59 -05:00
5gi
b96202a905 change aghain 2022-11-08 19:01:00 -05:00
5gi
96c950ccfe localchange 2022-11-08 18:59:47 -05:00
5gi
9677f95d60 a #6 2022-11-08 18:56:51 -05:00
5gi
78c8146fed a #5 2022-11-08 18:55:32 -05:00
5gi
13155c9112 a #4 2022-11-08 18:52:49 -05:00
5gi
ff8b5ea1aa a #3 2022-11-08 18:50:55 -05:00
5gi
dd495dc277 a #2 2022-11-08 18:42:40 -05:00
5gi
31268450e7 a 2022-11-08 18:37:33 -05:00
5gi
04bfc0fe22 add s.out.prtln comments 2022-11-08 11:09:02 -05:00
4 changed files with 107 additions and 43 deletions

View File

@ -16,5 +16,10 @@
<option name="name" value="MavenRepo" /> <option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" /> <option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://git.nevets.tech/api/packages/5gi/maven" />
</remote-repository>
</component> </component>
</project> </project>

View File

@ -1,24 +1,58 @@
# DeepJ # 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>
> Info
[To see more details, see the wiki](https://git.nevets.tech/5gi/DeepJ/wiki/Home#user-content-usage-setup).
________________________________________ ________________________________________
DeepJ is a Java Wrapper for the DeepL Free Public API. This was originally made by Steven (Forked From) and Updated by 5gi DeepJ is a Java Wrapper for the DeepL Free Public API. This was originally made by Steven (Forked From) and Updated by 5gi

View File

@ -5,12 +5,15 @@ plugins {
} }
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
group 'com.the5gi.deepj' group 'com.the5gi.deepj'
version '1.2.1' version '1.3.7'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11 sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url "https://git.nevets.tech/api/packages/5gi/maven"
}
} }
dependencies { dependencies {
@ -20,19 +23,20 @@ dependencies {
publishing { publishing {
publications{ publications{
publish(MavenPublication) { publish(MavenPublication) {
artifact("target/DeepJ-$version" + "-all.jar") { artifact("nexus/DeepJ-$version" + ".jar") {
extension 'jar' extension 'jar'
} }
} }
} }
repositories { repositories {
maven { maven {
name 'nexus' name 'gitea'
url "https://repo.nevets.tech/repository/maven-releases/" url "https://git.nevets.tech/api/packages/5gi/maven/"
credentials { credentials.username System.getenv('fivegiUserGit')
username System.getenv('nexusUser') credentials.password System.getenv('fivegiPassGit')
password System.getenv('nexusPass')
} }
} }
} }
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
} }

View File

@ -10,39 +10,61 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
public class Translator { public class Translator {
public static String globalAuthKey = "null"; public static String globalAuthKey = "null";
protected Request request;
public static void setGlobalAuthKey(String key) {
globalAuthKey = key;
}
private Request request;
public Translator() { public Translator() {
if (globalAuthKey == null) { if (globalAuthKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global Auth Key Translator Constructor." + 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");
"\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");
} else { } else {
request = new Request(globalAuthKey); request = new Request(globalAuthKey);
} }
} }
public Translator(String authKey) { public Translator(String authKey) {
if (!Objects.equals(globalAuthKey, "null")) { 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()\"" + 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 :)");
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)");
} }
request = new Request(authKey); request = new Request(authKey);
} }
public Translator(String authKey, boolean silence) { public Translator(String authKey, boolean silence) {
if (!Objects.equals(globalAuthKey, "null") && !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()\"" + 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 :)");
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
} }
request = new Request(authKey); request = new Request(authKey);
} }
public static void setGlobalAuthKey(String key) {
globalAuthKey = key;
}
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) {
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) { 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"; String response = "Error processing request";
try { try {
response = request.queryAPI(langToTranslateTo, sourceMessage); response = request.queryAPI(langToTranslateTo, sourceMessage);
@ -60,23 +82,22 @@ public class Translator {
return message; return message;
} }
protected static class Request { protected static class Request {
private final String authKey; public String authKey;
public Request(String authKey) { public Request(String authKey) {
this.authKey = authKey; this.authKey = authKey;
} }
public void setAuthKey(String key) {
authKey = key;
}
public String queryAPI(Language langEnum, String message) throws IOException, InterruptedException { public String queryAPI(Language langEnum, String message) throws IOException, InterruptedException {
String encodedAuthKey = URLEncoder.encode(authKey, StandardCharsets.UTF_8); String encodedAuthKey = URLEncoder.encode(authKey, StandardCharsets.UTF_8);
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().GET() 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();
.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()); HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString());
return response.body(); return response.body();
} }
} }
public enum Language { public enum Language {
Bulgarian("BG"), Bulgarian("BG"),
Czech("CS"), Czech("CS"),