Compare commits

..

1 Commits

Author SHA1 Message Date
5gi ☑
7af2b6e7cb I fixed some spelling mistakes. Otherwise, nothing changed. 2023-03-26 12:04:12 -04:00
4 changed files with 118 additions and 8 deletions

View File

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

View File

@ -2,8 +2,54 @@
[![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.4.2'
version '1.4.3'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11

View File

@ -1,4 +1,5 @@
package com.the5gi.DeepJ;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
@ -10,33 +11,83 @@ import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class Translator {
//REQUEST INSIDE OF TRANSLATOR
protected Request request;
//GLOBAL AUTH KEY (GAK)
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");
//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) {
//GAK (SILENCABLE)
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 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(String authKey) {
//NORMAL REQUEST (GAK Notice) (NO SILENCE)
if (!Objects.equals(globalAPIKey, "null")) {
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 :)");
}
request = new Request(authKey);
}
public Translator(String apiKey, boolean silence) {
//NORMAL REQUEST (GAK SILENCEABLE)
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 :)");
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 :)");
}
request = new Request(apiKey);
}
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) {
if (request.authKey == "null") {
System.out.println("[DeepJ] This translator is closed! Please re-create!");
@ -58,6 +109,8 @@ public class Translator {
}
return message;
}
//API REQUEST CLASS
protected static class Request {
public String authKey;
public Request(String authKey) {
@ -81,10 +134,12 @@ public class Translator {
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);
@ -92,19 +147,24 @@ public class Translator {
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 {
Bulgarian("BG"),
Czech("CS"),
@ -132,10 +192,14 @@ public class Translator {
Slovenian("SL"),
Swedish("SV"),
Chinese("ZH");
//API STRING IDENTIFIER
private final String apiString;
Language(String apiString) {
this.apiString = apiString;
}
//API STRING IDENTIFIER RETURN
public String getApiString() {
return this.apiString;
}