-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from LevineLiu/develop
add google translate
- Loading branch information
Showing
10 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/name/gudong/translate/mvp/model/ApiGoogle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package name.gudong.translate.mvp.model; | ||
|
||
import okhttp3.ResponseBody; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
import retrofit2.http.Streaming; | ||
import rx.Observable; | ||
|
||
/** | ||
* Created on 2017/2/22 | ||
* | ||
* @author Levine | ||
*/ | ||
|
||
public interface ApiGoogle { | ||
|
||
/** | ||
* http://translate.google.cn/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=google | ||
*/ | ||
@Streaming | ||
@GET("translate_a/single?client=gtx&dt=t&ie=UTF-8&oe=UTF-8&sl=auto") | ||
Observable<ResponseBody> translateGoogle( | ||
@Query("q") String q, | ||
@Query("tl") String targetLanguage | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/name/gudong/translate/mvp/model/entity/translate/GoogleResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package name.gudong.translate.mvp.model.entity.translate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import name.gudong.translate.mvp.model.type.ETranslateFrom; | ||
|
||
/** | ||
* Created on 2017/2/21 | ||
* | ||
* @author Levine | ||
*/ | ||
|
||
public class GoogleResult extends AbsResult{ | ||
|
||
/** | ||
* [[["谷歌","google",,,1]],,"en"] | ||
*/ | ||
private String translationResult; | ||
|
||
private List<String> getTranslation(){ | ||
List<String> translationList = new ArrayList<>(1); | ||
String[] translation = translationResult.replace("[", "").split("\","); | ||
translationList.add(translation[0].replace("\"", "")); | ||
return translationList; | ||
} | ||
|
||
@Override | ||
public List<String> wrapTranslation() { | ||
return getTranslation(); | ||
} | ||
|
||
@Override | ||
public List<String> wrapExplains() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public String wrapQuery() { | ||
return translationResult; | ||
} | ||
|
||
@Override | ||
public int wrapErrorCode() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String wrapEnPhonetic() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String wrapAmPhonetic() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String wrapEnMp3() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String wrapAmMp3() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String translateFrom() { | ||
return ETranslateFrom.GOOGLE.name(); | ||
} | ||
|
||
@Override | ||
public String wrapPhEn() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String wrapPhAm() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String wrapMp3Name() { | ||
return null; | ||
} | ||
|
||
public String getTranslationResult() { | ||
return translationResult; | ||
} | ||
|
||
public void setTranslationResult(String translationResult) { | ||
this.translationResult = translationResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters