Permalink
Browse files

adding basic translation features. will later port to just using goog…

…le translate API or MS api
  • Loading branch information...
1 parent f7db063 commit c9a927a594386add33d86e8c1e448126bd73d024 Addy Osmani committed Jun 13, 2011
Showing with 58 additions and 4 deletions.
  1. +2 −0 index.html
  2. +34 −0 js/mylibs/jquery.translate.js
  3. +22 −4 js/mylibs/speechBrowser.js
View
@@ -50,6 +50,7 @@
<script src="js/mylibs/speechBrowser.js"></script>
+
<!--[if lt IE 7 ]>
<script src="js/libs/dd_belatedpng.js"></script>
<script>DD_belatedPNG.fix("img, .png_bg");</script>
@@ -71,6 +72,7 @@
<script type="text/javascript" src="http://google.com/jsapi?key=ABQIAAAA5g3oldWeWxuPrTXKva9onBThuutJKBzNgiFSXrfV8d7em1iSJxTy2j4jgYplI_ynFqz-oxLfNc61Ag"></script>
<script type="text/javascript">google.load("search", "1");</script>
<script type="text/javascript" src="js/mylibs/gsearch.js"></script>
+<script type="text/javascript" src="js/mylibs/jquery.translate.js"></script>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -106,23 +106,41 @@ var speechBrowser = function(){
query: function(val){
//set qStr = val if you want to test without speaking.
- var qStr = speech.val();
+ var qStr = val;//speech.val();
+ var stage = $('#search-results');
this.prepareStage();
console.log(qStr);
if(qStr !== null){
var defineTest = $.trim(this.getQueryStartsWith('define',qStr)),
- searchTest = $.trim(this.getQueryStartsWith('search',qStr));
+ searchTest = $.trim(this.getQueryStartsWith('search', qStr)),
+ frenchTest = $.trim(this.getQueryStartsWith('french', qStr)),
+ germanTest = $.trim(this.getQueryStartsWith('german', qStr));
console.log('def test:' + defineTest);
if(searchTest.length > 0){
this.textToSpeech('i hope these results for' + searchTest + ' help ');
- $("#search-results").gSearch({search_text : searchTest ,count:4,pagination:true});
+ stage.gSearch({search_text : searchTest ,count:4,pagination:true});
}else if(defineTest.length >0){
this.getDictionaryDefinition($.trim(defineTest));
+ }else if(translateTest.length >0){
+
+ stage.html(qStr);
+ stage.translate('en','fr', function(){
+ speechBrowser.textToSpeech( 'the french translation is ' + stage.html() );
+ });
+
+ }else if(translateTest.length >0){
+
+ stage.html(qStr);
+ stage.translate('en','de', function(){
+ speechBrowser.textToSpeech( 'the german translation is ' + stage.html() );
+ });
+
+
}else{
/*if not performing a search check for other shortcuts supported*/
@@ -249,7 +267,7 @@ var speechBrowser = function(){
$(function($) {
speechBrowser.init();
- //speechBrowser.query('search house');
+ speechBrowser.query('french house');
});

0 comments on commit c9a927a

Please sign in to comment.