Compare commits

..

No commits in common. "master" and "1.2.1" have entirely different histories.

5 changed files with 48 additions and 183 deletions

View File

@ -16,10 +16,5 @@
<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

@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="corretto-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="temurin-11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,58 +1,24 @@
# 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,15 +5,12 @@ plugins {
} }
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
group 'com.the5gi.deepj' group 'com.the5gi.deepj'
version '1.4.3' version '1.2.1'
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 {
@ -23,20 +20,19 @@ dependencies {
publishing { publishing {
publications{ publications{
publish(MavenPublication) { publish(MavenPublication) {
artifact("nexus/DeepJ-$version" + ".jar") { artifact("target/DeepJ-$version" + "-all.jar") {
extension 'jar' extension 'jar'
} }
} }
} }
repositories { repositories {
maven { maven {
name 'gitea' name 'nexus'
url "https://git.nevets.tech/api/packages/5gi/maven/" url "https://repo.nevets.tech/repository/maven-releases/"
credentials.username System.getenv('fivegiUserGit') credentials {
credentials.password System.getenv('fivegiPassGit') username System.getenv('nexusUser')
password System.getenv('nexusPass')
}
} }
} }
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
} }

View File

@ -10,89 +10,39 @@ 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";
//REQUEST INSIDE OF TRANSLATOR public static void setGlobalAuthKey(String key) {
protected Request request; globalAuthKey = key;
//GLOBAL AUTH KEY (GAK)
public static String globalAPIKey = "null";
//CONSTRUCTORS
public Translator() {
//GAK
if (globalAPIKey == null) {
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 constructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
} else {
request = new Request(globalAPIKey);
}
} }
public Translator(boolean silent) { private Request request;
//GAK (SILENCABLE) public Translator() {
if (globalAPIKey == null && !silent) { if (globalAuthKey == null) {
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 constructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n"); 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");
} else { } else {
request = new Request(globalAPIKey); request = new Request(globalAuthKey);
} }
} }
public Translator(String authKey) { public Translator(String authKey) {
//NORMAL REQUEST (GAK Notice) (NO SILENCE) if (!Objects.equals(globalAuthKey, "null")) {
if (!Objects.equals(globalAPIKey, "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 API key already! You can use if by just typing \"new Translator()\"" + "\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 apiKey, boolean silence) { public Translator(String authKey, boolean silence) {
//NORMAL REQUEST (GAK SILENCEABLE) if (!Objects.equals(globalAuthKey, "null") && !silence) {
if (!Objects.equals(globalAPIKey, "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 API key already! You can use if by just typing \"new Translator()\"" + "\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(apiKey); request = new Request(authKey);
} }
public static void setGlobalAPIKey(String key) {
//SET GLOBAL API KEY (STATIC)
globalAPIKey = key;
}
public static Translator newTranslator(String apiKey) {
//NORMAL REQUEST (NO GAK) (STATIC)
return new Translator(apiKey);
}
public static TranslatorBuilder newBuilder() {
return new TranslatorBuilder();
}
public static Translator newTranslator() {
//GAK (STATIC)
if (globalAPIKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global API Key \".of()\" Translator." +
"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAPIKey(String key)\" and then re-use this method." +
"\n[DeepJ] If you want to define an different authkey every time do: \"Translator.of(String apiKey)\"\n");
return new Translator("null");
} else {
return new Translator();
}
}
//END CONSTRUCTORS
//API KEYS
public void setAPIKey(String key) {
request.setAuthKey(key);
}
public String getAPIKey() {
return request.authKey;
}
public void close() {
request = new Request("null");
}
//END API KEYS
//TRANSLATE
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);
@ -109,62 +59,24 @@ public class Translator {
} }
return message; return message;
} }
//API REQUEST CLASS
protected static class Request { protected static class Request {
public String authKey; private final 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();
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()
HttpRequest request = HttpRequest.newBuilder() .header("Accept","*/*")
.GET() .header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept","*/*") .uri(URI.create("https://api-free.deepl.com/v2/translate?auth_key=" + encodedAuthKey + "&target_lang=" + langEnum.getApiString() + "&text=" + encodedMessage)).build();
.header("Content-Type", "application/x-www-form-urlencoded") HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
.uri(deepLURI)
.build();
HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString());
return response.body(); 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;
}
}
//DEEPL LANGUAGES
public enum Language { public enum Language {
Bulgarian("BG"), Bulgarian("BG"),
Czech("CS"), Czech("CS"),
@ -192,16 +104,12 @@ public class Translator {
Slovenian("SL"), Slovenian("SL"),
Swedish("SV"), Swedish("SV"),
Chinese("ZH"); Chinese("ZH");
//API STRING IDENTIFIER
private final String apiString; private final String apiString;
Language(String apiString) { Language(String apiString) {
this.apiString = apiString; this.apiString = apiString;
} }
//API STRING IDENTIFIER RETURN
public String getApiString() { public String getApiString() {
return this.apiString; return this.apiString;
} }
} }
} }