Skip to content

Commit

Permalink
Fixed Google API call failure. Close #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ringosham committed Jul 1, 2021
1 parent 2c27c18 commit 53b5506
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions .idea/modules/TranslationMod.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions .idea/modules/TranslationMod.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
minecraft_version=1.16.5
forge_version=1.16.5-36.0.42
mappings_channel=snapshot
mappings_version=20201028-1.16.3
mappings_version=20210309-1.16.5
mod_version=6.0
# suppress inspection "UnusedProperty"
mod_id=translationmod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public RequestResult translate(String message, Language from, Language to) {
//Signature
//Must use unencoded message for signature
queryParam.put("sign", sign(ConfigManager.config.baiduAppId.get(), message, salt, ConfigManager.config.baiduKey.get()));
Response response = POST(queryParam, "application/x-www-form-urlencoded");
Response response = sendRequest("POST", queryParam, "application/x-www-form-urlencoded");
if (response.getResponseCode() == 200) {
//Baidu does not follow standard REST response codes at all. It's 200 regardless of success or failure
//This is utterly retarded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public RequestResult translate(String message, Language from, Language to) {
queryParam.put("dt", "t");
queryParam.put("q", encodedMessage);
try {
Response response = POST(queryParam, "application/json");
Response response = sendRequest("GET", queryParam, "application/json");
//Usually Google would just return 429 if they deny access, but just in case it gives any other HTTP error codes
if (response.getResponseCode() != 200) {
accessDenied = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public RequestResult translate(String message, Language from, Language to) {
if (from != LangManager.getInstance().getAutoLang()) {
queryParam.put("source", from.getGoogleCode());
}
Response response = POST(queryParam, "application/json");
Response response = sendRequest("GET", queryParam, "application/json");
String responseString = response.getEntity();
Gson gson = new Gson();
if (response.getResponseCode() == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public RequestResult translateAuto(String message, Language to) {
public abstract RequestResult translate(String message, Language from, Language to);


protected Response POST(Map<String, String> queryParams, String contentType) {
protected Response sendRequest(String method, Map<String, String> queryParams, String contentType) {
StringBuilder requestUrl = new StringBuilder(baseUrl);
boolean firstParam = true;
for (String key : queryParams.keySet()) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,7 @@
- RMV: Yandex translations. They've proofed to be quite unreliable and since they removed the free option. There's no reason to keep using it.
5.1.1 - FIX: Translation client encoding problem (#1)
- FIX: Wrongly reading acacia buttons as acacia wall signs (#2)
6.0 - ADD: Baidu translation. For people from North Korea and "other countries"
- FIX: Translator crash due to previously failed translation
6.0 - ADD: Baidu translation. For people from North Korea and "other countries" (#8)
- FIX: Translator crash due to previously failed translation (#11)
- FIX: Failed to get chat log from regex screen (#10)
- FIX: Google translate API call error (#14)

0 comments on commit 53b5506

Please sign in to comment.