forked from 5gi/DeepJ
Added ".close()" to Translator
closes Translator and Request
This commit is contained in:
parent
fab65fde3a
commit
15368ab222
@ -12,41 +12,28 @@ 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";
|
||||||
public static void setGlobalAuthKey(String key) {
|
|
||||||
globalAuthKey = key;
|
|
||||||
}
|
|
||||||
protected Request request;
|
protected 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 void setAuthKey(String key) {
|
public static void setGlobalAuthKey(String key) {
|
||||||
request.setAuthKey(key);
|
globalAuthKey = key;
|
||||||
}
|
|
||||||
public void setAPIKey(String authKey) {
|
|
||||||
request = new Request(authKey);
|
|
||||||
}
|
|
||||||
public String getAPIKey() {
|
|
||||||
return request.authKey;
|
|
||||||
}
|
}
|
||||||
public static Translator of(String authKey) {
|
public static Translator of(String authKey) {
|
||||||
return new Translator(authKey);
|
return new Translator(authKey);
|
||||||
@ -61,9 +48,21 @@ public class Translator {
|
|||||||
return new Translator();
|
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") {
|
if (request.authKey == "null") {
|
||||||
System.out.println("[DeepJ] This translator is null! Please recreate!");
|
System.out.println("[DeepJ] This translator is closed! Please re-create!");
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
String response = "Error processing request";
|
String response = "Error processing request";
|
||||||
|
Loading…
Reference in New Issue
Block a user