diff --git a/src/main/java/com/the5gi/DeepJ/Translator.java b/src/main/java/com/the5gi/DeepJ/Translator.java index 7fa70f5..9e9f36e 100644 --- a/src/main/java/com/the5gi/DeepJ/Translator.java +++ b/src/main/java/com/the5gi/DeepJ/Translator.java @@ -15,7 +15,7 @@ public class Translator { public static void setGlobalAuthKey(String key) { globalAuthKey = key; } - private Request request; + protected Request request; public Translator() { if (globalAuthKey == null) { /* @@ -52,13 +52,38 @@ instead of "new Translator(String authKey)". NOTE: This will work but just some } request = new Request(authKey); } + public void setAuthKey(String key) { + request.setAuthKey(key); + } public void setAPIKey(String authKey) { request = new Request(authKey); } public String getAPIKey() { return request.authKey; } + public static Translator of(String authKey) { + return new Translator(authKey); + } + public static Translator of() { + 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 \".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 String translate(Language langToTranslateTo, String sourceMessage) { + if (request.authKey == "null") { + System.out.println("[DeepJ] This translator is null! Please recreate!"); + return; + } String response = "Error processing request"; try { response = request.queryAPI(langToTranslateTo, sourceMessage); @@ -80,6 +105,9 @@ instead of "new Translator(String authKey)". NOTE: This will work but just some 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);