Important: The Google Translate API has been officially deprecated as of May 26, 2011. Due to the substantial economic burden caused by extensive abuse, the number of requests you may make per day will be limited and the API will be shut off completely on December 1, 2011. For website translations, we encourage you to use the Google Translate Element.
We not only open our code, also the mind. 
Notice:
  • You only need to download Google Translate Kit; Google Translate Kit Plus is for sqlite caching and further additional features.
  • "JavaImpl" is added since [change set 2527]  
  • source code is divided into "ggltranslate" & "plus" since [change set 2315 ]
Hello all, if you are similar with Unit Testing in C# or like to learn about it, join us contact: jebberwocky@gmail.com

Project Description
 It is a sub-project divided from Citiport project. Google Translation Kit is an implementation for Google Translation in C#, also supporting cache and data writing to any media, log file, database or...
Very basic sample:
public void OnEvent(object sender, GglTranslateEventAgrs e)
{
	sb.Append(e.TranslatedPost.text);
}

protected void Page_Load(object sender, EventArgs e)
{
	sb = new StringBuilder();
	Translator gt = new Translator();
	/*using cache*/
	gt.KeyGen = new SimpleKeyGen();
	gt.CacheManager = new SimleCacheManager();
	//gt.Writer = dw; deprecated 0.50
	gt.OnTranslatedHandler += new GglTranslateEventHandler(OnEvent);
	Translator.TranslatedPost post = gt.GetTranslatedPost("Hello world", LanguageConst.ENGLISH, LanguageConst.CHINESE);
	Translator.TranslatedPost post2 = gt.GetTranslatedPost("I'm Jeff", LanguageConst.ENGLISH, LanguageConst.CHINESE);
	this.result.InnerHtml = "<p>" + post.text +post2.text+ "</p>";
	File.WriteAllText(HttpContext.Current.Server.MapPath("/txt/test.log"), sb.ToString());
}
Sample with SqliteCache( it is still a rough implementation, please feel free to drop feedback)
  • dependency 
    • System.Data.Sqlite 1.0.66.0
String file = Server.MapPath("/App_Data/db");
Translator gt = new Translator();
gt.KeyGen = new SimpleKeyGen();
SqliteCacheManager cache = new SqliteCacheManager();
cache.FileLocation = file;
gt.CacheManager = cache;
Translator.TranslatedPost post = gt.GetTranslatedPost("Hello world", LanguageConst.ENGLISH, LanguageConst.CHINESE);
Translator.TranslatedPost post2 = gt.GetTranslatedPost("I'm Jeff", LanguageConst.ENGLISH, LanguageConst.CHINESE);
this.result.InnerHtml = "<p>" + post.text + post2.text + "</p>";
In Java 
dependency 
  • Json-simple-1.1.jar

 

private class FooListener implements GglTranslateListener{
	
	@Override
	public void onTranslated(GglTranslateEvent evt) {
		if(evt.getType() == GglTranslateEvent.CONTENTS_TRANSLATED){
			System.out.println("CONTENT"+evt.getPost().getText());
		}
	}
	
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	GoogleTranslator translator = new GoogleTranslator();
	translator.addGglTranslateListener(new FooListener());//Since 0.2.0
	TranslatedPost post = translator.GetTranslatedPost("hello world", LangConst.ENGLISH, LangConst.CHINESE);
	response.setCharacterEncoding(GoogleTranslator.getTextCharset());//@since 0.0.2
	response.getWriter().append(post.getText());
}

 

Performance & Code Quality

 

 

For any question or suggestion, contact jebberwocky@gmail.com or leave message in "Discussions" :)

Last edited May 29, 2011 at 8:24 AM by jebberwocky, version 32