Removes Google translate
This commit is contained in:
parent
f3063634c4
commit
18508ac1f8
|
@ -211,7 +211,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
LinearLayout status_container3;
|
||||
LinearLayout main_container;
|
||||
TextView yandex_translate;
|
||||
TextView google_translate;
|
||||
LinearLayout status_action_container;
|
||||
LinearLayout status_replies;
|
||||
LinearLayout status_replies_profile_pictures;
|
||||
|
@ -261,7 +260,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
status_spoiler = itemView.findViewById(R.id.status_spoiler);
|
||||
status_spoiler_button = itemView.findViewById(R.id.status_spoiler_button);
|
||||
yandex_translate = itemView.findViewById(R.id.yandex_translate);
|
||||
google_translate = itemView.findViewById(R.id.google_translate);
|
||||
status_replies = itemView.findViewById(R.id.status_replies);
|
||||
status_replies_profile_pictures = itemView.findViewById(R.id.status_replies_profile_pictures);
|
||||
new_element = itemView.findViewById(R.id.new_element);
|
||||
|
@ -438,19 +436,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
{
|
||||
case Helper.TRANS_NONE:
|
||||
holder.yandex_translate.setVisibility(View.GONE);
|
||||
holder.google_translate.setVisibility(View.GONE);
|
||||
break;
|
||||
case Helper.TRANS_YANDEX:
|
||||
holder.google_translate.setVisibility(View.GONE);
|
||||
holder.yandex_translate.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case Helper.TRANS_GOOGLE:
|
||||
holder.yandex_translate.setVisibility(View.GONE);
|
||||
holder.google_translate.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
default:
|
||||
holder.yandex_translate.setVisibility(View.GONE);
|
||||
holder.google_translate.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -925,13 +916,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
context.startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
holder.google_translate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://translate.google.com/"));
|
||||
context.startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
//Spoiler opens
|
||||
holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -223,7 +223,6 @@ public class Helper {
|
|||
public static final int LED_COLOUR = 0;
|
||||
|
||||
public static final int TRANS_YANDEX = 0;
|
||||
public static final int TRANS_GOOGLE = 1;
|
||||
public static final int TRANS_NONE = 2;
|
||||
|
||||
public static final String SET_TRANS_FORCED = "set_trans_forced";
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.translation;
|
||||
|
||||
|
||||
|
||||
import com.loopj.android.http.AsyncHttpClient;
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
|
||||
|
||||
class GoogleTranslateClient {
|
||||
|
||||
private static final String BASE_URL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&ie=UTF-8&oe=UTF-8&";
|
||||
|
||||
|
||||
private static AsyncHttpClient client = new AsyncHttpClient();
|
||||
|
||||
public static void get(String text, String toLanguage, AsyncHttpResponseHandler responseHandler) {
|
||||
client.post(getAbsoluteUrl(text, toLanguage), responseHandler);
|
||||
}
|
||||
|
||||
private static String getAbsoluteUrl(String content, String toLanguage) {
|
||||
toLanguage = toLanguage.replace("null","");
|
||||
String lang = "tl=" + toLanguage + "&dt=t&";
|
||||
String text;
|
||||
try {
|
||||
text = "q=" + URLEncoder.encode(content, "utf-8") + "&";
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
text = "q=" + content + "&";
|
||||
}
|
||||
String format = "format=html&";
|
||||
return BASE_URL + lang + format + text ;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.translation;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
||||
import org.json.JSONException;
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 12/07/2017.
|
||||
* Google client API
|
||||
*/
|
||||
class GoogleTranslateQuery {
|
||||
|
||||
private OnTranslatedInterface listener;
|
||||
|
||||
|
||||
GoogleTranslateQuery(OnTranslatedInterface listenner) {
|
||||
this.listener = listenner;
|
||||
}
|
||||
|
||||
void getGoogleTextview(final Translate translate, final Status status, final String text, final String toLanguage) throws JSONException {
|
||||
|
||||
GoogleTranslateClient.get(text, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslatedTextview(translate, status, str_response,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
|
||||
listener.onTranslatedTextview(translate, status, null, true);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void getGoogleTranslation(final Translate translate, final Helper.targetField target, final String text, final String toLanguage) throws JSONException {
|
||||
|
||||
GoogleTranslateClient.get(text, toLanguage, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
|
||||
String str_response = new String(response);
|
||||
listener.onTranslated(translate, target, str_response,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
|
||||
listener.onTranslated(translate, target, null, true);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -176,23 +176,10 @@ public class Translate {
|
|||
new YandexQuery(this.listener).getYandexTranslation(this, Helper.targetField.STATUS, content, this.targetedLanguage);
|
||||
if (targetField == Helper.targetField.CW)
|
||||
new YandexQuery(this.listener).getYandexTranslation(this, Helper.targetField.CW, content, this.targetedLanguage);
|
||||
} else {
|
||||
while (text.length() > 0 && text.charAt(text.length() - 1) == '\n' && text.length() > 0)
|
||||
text = text.substring(0, text.length() - 1);
|
||||
text += ".";
|
||||
if (content != null)
|
||||
new GoogleTranslateQuery(this.listener).getGoogleTranslation(this, Helper.targetField.STATUS, text, this.targetedLanguage);
|
||||
if (targetField == Helper.targetField.CW)
|
||||
new GoogleTranslateQuery(this.listener).getGoogleTranslation(this, Helper.targetField.CW, content, this.targetedLanguage);
|
||||
}
|
||||
}else {
|
||||
if (translator == Helper.TRANS_YANDEX) {
|
||||
new YandexQuery(this.listener).getYandexTextview(this, this.status, content, this.targetedLanguage);
|
||||
} else {
|
||||
while (text.length() > 0 && text.charAt(text.length() - 1) == '\n' && text.length() > 0)
|
||||
text = text.substring(0, text.length() - 1);
|
||||
text += ".";
|
||||
new GoogleTranslateQuery(this.listener).getGoogleTextview(this, this.status, text, this.targetedLanguage);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -212,8 +199,6 @@ public class Translate {
|
|||
try {
|
||||
if (translator == Helper.TRANS_YANDEX)
|
||||
aJsonString = yandexTranslateToText(translatedResult);
|
||||
else if( translator == Helper.TRANS_GOOGLE)
|
||||
aJsonString = googleTranslateToText(translatedResult);
|
||||
if( aJsonString == null)
|
||||
return null;
|
||||
|
||||
|
@ -281,41 +266,4 @@ public class Translate {
|
|||
aJsonString = URLDecoder.decode(aJsonString, "UTF-8");
|
||||
return aJsonString;
|
||||
}
|
||||
|
||||
private String googleTranslateToText(String text) throws JSONException, UnsupportedEncodingException{
|
||||
|
||||
int i = 0;
|
||||
StringBuilder aJsonString = new StringBuilder();
|
||||
while( i < new JSONArray(new JSONArray(text).get(0).toString()).length() ) {
|
||||
aJsonString.append(new JSONArray(new JSONArray(new JSONArray(text).get(0).toString()).get(i).toString()).get(0).toString());
|
||||
i++;
|
||||
}
|
||||
//Some fixes due to translation with Google
|
||||
aJsonString = new StringBuilder(aJsonString.toString().trim());
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace("< / ", "</"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace("</ ", "</"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace("> ", ">"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace(" <", "<"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace(" // ", "//"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace("// ", "//"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace(" //", "//"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace(" www .", "www."));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replace("www .", "www."));
|
||||
|
||||
// This one might cause more trouble than it's worth
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replaceAll("\\* \\.", "*."));
|
||||
|
||||
/*
|
||||
Noticed that sometimes the special tags were getting messed up by Google,
|
||||
might be other variants, only caught one so far.
|
||||
|
||||
But, pre-planning might save some time later...
|
||||
*/
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replaceAll("__\\s?([ut])\\s?(\\d+)\\s?__", "__$1$2__"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replaceAll("%(?![0-9a-fA-F]{2})", "%25"));
|
||||
aJsonString = new StringBuilder(aJsonString.toString().replaceAll("\\+", "%2B"));
|
||||
aJsonString = new StringBuilder(URLDecoder.decode(aJsonString.toString(), "UTF-8"));
|
||||
return aJsonString.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -190,15 +190,6 @@
|
|||
android:text="Powered by Yandex.Translate"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="HardcodedText" />
|
||||
<TextView
|
||||
android:id="@+id/google_translate"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="2dp"
|
||||
android:gravity="end"
|
||||
android:text="Powered by Google Translate"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -342,7 +342,6 @@
|
|||
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>Nein</item>
|
||||
</string-array>
|
||||
|
||||
|
|
|
@ -331,7 +331,6 @@
|
|||
</string-array>
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>Non</item>
|
||||
</string-array>
|
||||
|
||||
|
|
|
@ -334,7 +334,6 @@
|
|||
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>Nee</item>
|
||||
</string-array>
|
||||
|
||||
|
|
|
@ -335,7 +335,6 @@
|
|||
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>Não</item>
|
||||
</string-array>
|
||||
|
||||
|
|
|
@ -341,7 +341,6 @@
|
|||
|
||||
<string-array name="settings_translation">
|
||||
<item>Yandex</item>
|
||||
<item>Google</item>
|
||||
<item>No</item>
|
||||
</string-array>
|
||||
|
||||
|
|
Loading…
Reference in New Issue