Android Open Source - book Translator

From Project

Back to project page book.


The source code is released under:

MIT License

If you think the Android project book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package translator;
//from   w w w . j av  a  2 s  .  co  m
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;

import android.os.AsyncTask;
import book.Book;

import com.Db;

 * translates almost any language into something awful which does not make any sense in any language.

public class Translator{
  private Db db;

  public Translator(Db db){  
    this.db = db;
  public Book translate(Book book){
    HashMap<String , List<String>> words = book.getWords();
    for (String word : words.keySet()){
      book.addTranslations(word, this.translate(word));
    return book;
  public List<String> translate(String word){    
    if (this.db.hasTranslations(word)){    
      return this.db.getTranslations(word);
    } else {
      AsyncTask translation = new TranslateWordTask().execute(word);
      try {
        String translated = (String) translation.get();
        List<String> result = new ArrayList<String>();
        result.add( translated );
        return result;
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
      } catch (ExecutionException e) {
        // TODO Auto-generated catch block
      return null;

Java Source Code List