mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 16:29:39 +00:00
Proper Reformating
This commit is contained in:
1 parent
ce75880aba
commit
180d257024
1179 files changed
+59847
-61583
No files matched your search
@@ -14,40 +14,40 @@ import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class TranslateUtil {
|
||||
private static final String TranslateUrl = "http://translate.google.com/translate_a/t?client=t&text=%s&hl=en&sl=%s&tl=%s&ie=UTF-8&oe=UTF-8&multires=1&otf=1&pc=1&trs=1&ssel=3&tsel=6&sc=1";
|
||||
private static final String AudioUrl = "http://translate.google.com/translate_tts?q=%s&tl=%s";
|
||||
private static final String TranslateUrl = "http://translate.google.com/translate_a/t?client=t&text=%s&hl=en&sl=%s&tl=%s&ie=UTF-8&oe=UTF-8&multires=1&otf=1&pc=1&trs=1&ssel=3&tsel=6&sc=1";
|
||||
private static final String AudioUrl = "http://translate.google.com/translate_tts?q=%s&tl=%s";
|
||||
|
||||
public static String Translate(String text){
|
||||
public static String Translate(String text) {
|
||||
|
||||
try {
|
||||
String urlStr = String.format(TranslateUrl, URLEncoder.encode(text,"utf8"), "auto", "nl");
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
try {
|
||||
String urlStr = String.format(TranslateUrl, URLEncoder.encode(text, "utf8"), "auto", "nl");
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
|
||||
connection.setRequestProperty("X-HTTP-Method-Override", "GET");
|
||||
//connection.setRequestProperty("referer", "accounterlive.com");
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line = reader.readLine();
|
||||
reader.close();
|
||||
connection.disconnect();
|
||||
if(line != null){
|
||||
String parsed = parseJson(line);
|
||||
if(parsed != null)
|
||||
return parsed;
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
|
||||
connection.setRequestProperty("X-HTTP-Method-Override", "GET");
|
||||
//connection.setRequestProperty("referer", "accounterlive.com");
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line = reader.readLine();
|
||||
reader.close();
|
||||
connection.disconnect();
|
||||
if (line != null) {
|
||||
String parsed = parseJson(line);
|
||||
if (parsed != null)
|
||||
return parsed;
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// public static void PlayAudio(String text){
|
||||
// try {
|
||||
@@ -80,16 +80,16 @@ public class TranslateUtil {
|
||||
// }
|
||||
// }
|
||||
|
||||
private static String parseJson(String line) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(line);
|
||||
while(element.isJsonArray()){
|
||||
JsonArray array = (JsonArray) element;
|
||||
if(array.size() == 0)
|
||||
return null;
|
||||
element = array.get(0);
|
||||
}
|
||||
// System.out.println(element.getAsString());
|
||||
return element.getAsString();
|
||||
}
|
||||
private static String parseJson(String line) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(line);
|
||||
while (element.isJsonArray()) {
|
||||
JsonArray array = (JsonArray) element;
|
||||
if (array.size() == 0)
|
||||
return null;
|
||||
element = array.get(0);
|
||||
}
|
||||
// System.out.println(element.getAsString());
|
||||
return element.getAsString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user