2013-08-06 2 views
3

번역 나는 구글이 다음 코드를 사용하여 작업을 번역 시작 안드로이드 응용 프로그램을 개발 한 data은 null입니다. 따라서 Google 번역에서 번역 된 텍스트를 다시 내 신청서로 되돌릴 방법이 없다고 가정합니다. 이 올바른지?반환 번역 텍스트 활동

또한이를 수행 할 방법이있는 경우 API 서비스 약관을 위반하게됩니까? Google 번역 오프라인 언어 팩/번역을 사용하는 경우에도 여전히 위반 사항입니까?

Google 개발자 (직원)가이 문제를 보았을 때 몸무게가 늘어나면 감사하겠습니다. 나는 공식적인 응답을 정말로 찾고있다.

감사합니다.

+0

대신 [Google Translate API] (https://developers.google.com/translate/) (무료가 아닌)를 사용해야합니다. – ozbek

+0

예, 동의합니다. 고객의 문의를 만족시키기 위해 위 질문에 대한 공식 확인을 받으려합니다. – littleK

답변

1

또한 이것이 가능한지 궁금합니다.

here 간단한 텍스트를 Google Translate Http Service으로 묶는 클래스로 변환해야하는 경우.

합법적인지 확실하지 않기 때문에 프로덕션 환경에서 사용한 적이 없습니다 (출시 된 앱 읽기).

그래서 Google (직원)이 귀하의 질문에 답변한다면 ..이 접근법이 합법적인지 알려주시겠습니까?

여기 편리 구글 번역 HTTP 서비스를 감싸는 간단한 AsyncTask를 들어

가 :

import java.io.IOException; 
    import java.util.Arrays; 
    import java.util.Collections; 
    import java.util.Locale; 
    import java.util.Random; 

    import org.json.JSONArray; 
    import org.json.JSONException; 
    import org.json.JSONObject; 

    import android.os.AsyncTask; 
    import android.os.Bundle; 
    import android.util.Log; 

    import com.lus.android.net.RESTClient; 

    public class TranslatorTask extends AsyncTask<Bundle, Void, String> { 

     static final private String TAG = "TRANSLATOR"; 

     static final private String[] UA_LIST = { 
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0", 
      "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2", 
      "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:22.0) Gecko/20130328 Firefox/22.0", 
      "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20130405 Firefox/22.0", 
      "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; InfoPath.1; SV1; .NET CLR 3.8.36217; WOW64; en-US)", 
      "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; .NET CLR 2.7.58687; SLCC2; Media Center PC 5.0; Zune 3.4; Tablet PC 3.6; InfoPath.3)", 
      "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)", 
      "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)" 
     }; 


     public interface OnTranslatorTaskListener { 
      void onTextTranslated(String value); 
     }; 

     private OnTranslatorTaskListener mCallback = null; 


     public void setOnTranslatorTaskListener(OnTranslatorTaskListener listener) { 
      mCallback = listener; 
     } 

     @Override 
     protected String doInBackground(Bundle... params) { 
      if (params == null) return null; 

      Collections.shuffle(Arrays.asList(UA_LIST)); 

      String json = null; 

      RESTClient rest = null; 
      try { 
       rest = new RESTClient("http://translate.google.com/translate_a/t"); 
       rest.header("User-Agent", UA_LIST[new Random().nextInt(UA_LIST.length)]); 
       rest.data("client", "j"); //t = TEXT 
       rest.data("ie", "UTF-8"); 
       rest.data("oe", "UTF-8"); 

       rest.data("hl", params[0].getString("hl")); //, Locale.getDefault().getLanguage())); 
       rest.data("sl", params[0].getString("sl")); 
       rest.data("tl", params[0].getString("tl")); 
       rest.data("q", params[0].getString("text")); 

       json = rest.execute(); 

      } catch (IOException ioe) { 
       Log.e(TAG, ioe.getMessage(), ioe); 

      } finally { 
       if (rest != null) rest.shutdown(); 
      } 

      if (json == null) return null; 

      StringBuffer result = new StringBuffer(); 
      try { 
       JSONObject jo = new JSONObject(json); 
       if (jo.has("sentences")) { 
        JSONArray ja = jo.getJSONArray("sentences"); 
        for (int i = 0; i < ja.length(); i++) { 
         JSONObject item = ja.getJSONObject(i); 
         if (item.has("trans")) 
          result.append(item.getString("trans")); 
        } 
       } 
      } catch (JSONException je) { 
       Log.e(TAG, je.getMessage(), je); 
      } 

      return result.toString(); 
     } 


     @Override 
     protected void onPostExecute(String result) { 
      if (result != null && mCallback != null) 
       mCallback.onTextTranslated(result); 
     } 
    }; 

에서 [위해 RESTClient 클래스] HttpClient를에 래퍼입니다, 당신은 발견 할 수있는 source code here

감사합니다,

luca

+0

안녕 루카. 좋은 물건이지만 문제가되는 것 같습니다 : json = rest.execute(); execute 메소드는 부울을 반환합니다. – Yster

+1

고마워요 @Yster 오랜 시간이 걸렸습니다. 어쩌면 Google API가 바뀌었을 것입니다 (먼저 게임을 시도해보십시오). 내 오래된 RESTClient 대신 안드로이드 발리를 사용하십시오. 응답을 기록하려면 다음을 사용하십시오. rest.setDebug (true); 그런 다음 쉘에서 ./adb 쉘 setprop log.tag.org.apache.http VERBOSE ./adb 쉘 setprop log.tag.org.apache.http.wire VERBOSE ./adb 쉘 setprop log.tag.org. apache.http.headers VERBOSE –

+0

답장을 보내 주셔서 감사합니다, Luca. 내가 발리슛으로 무엇인가를 결정할 수 있는지 알게 될 것이다. – Yster