{"id":20578,"date":"2016-03-10T03:01:06","date_gmt":"2016-03-09T17:01:06","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=20578"},"modified":"2016-03-10T11:15:55","modified_gmt":"2016-03-10T01:15:55","slug":"google-translate-english-phrasal-verbs-and-idioms-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/google-translate-english-phrasal-verbs-and-idioms-tutorial\/","title":{"rendered":"Google Translate English Phrasal Verbs and Idioms Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Google Translate English Phrasal Verbs and Idioms Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressionschalkboard.jpg\" title=\"Google Translate English Phrasal Verbs and Idioms Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Google Translate English Phrasal Verbs and Idioms Tutorial<\/p><\/div>\n<p>A couple of our recent <a target=_blank title='ESL information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/English_as_a_second_or_foreign_language'>ESL<\/a> tutorials regarding Phrasal Verbs (<a target=_blank title='English Expressions and Idioms Game Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/english-phrasal-verb-game-primer-tutorial\/'>English Phrasal Verb Game Primer Tutorial<\/a>) and English Expressions and Idioms (as with <a title='English Expressions and Idioms Game Primer Tutorial' href='#eeaigpt'>English Expressions and Idioms Game Primer Tutorial<\/a> below) have a lot in common, especially their capacity to baffle a non-native English speaker.<\/p>\n<p>With this in mind we introduce some new optional functionality that may help out an ESL student completely flummoxed with a Phrasal Verb or an English Expression or Idiom by using Google Translate to translate the phrase or idiom back to their mother tongue.  Obviously, this translation could well be imperfect, but it is designed with a view to the user having no idea where to start understanding the English presented to them.<\/p>\n<p>And so we &#8220;house&#8221; this new functionality in some external Javascript which was <i>almost<\/i> okay to just plug into our two other HTML <i>parents<\/i> but not quite.<\/p>\n<p>Maybe you wonder how it can get even close?  Glad you asked &#8230; well, we like to add external Javascript and design it as independently as possible, so that it can be called by either method below, the latter being an address bar URL and the former being in the HTML&#8217;s <i>head<\/i> section, to become <b>active<\/b> &#8230;<\/p>\n<ol>\n<li><code>&lt;script src='translate_hear.js<b>?translate_hear=yes<\/b>' type='text\/javascript'&gt;&lt;\/script&gt;<\/code><\/li>\n<li><code>http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html<b>?translate_hear=yes<\/b><\/code><\/li>\n<\/ol>\n<p> &#8230; and only once this is established, the independently minded external Javascript looks for <i>&gt;.&lt;\/a&gt;<\/i> within <i>document.body.innerHTML<\/i> &#8230; I mean, who&#8217;d be crazy enough to have a link to a dot (.) &#8230; oops! &#8230; anyway &#8230;<\/p>\n<p> &#8230; then we store away (in global var<font size=1>iable<\/font> <i>alist<\/i>&#8216;s global var<font size=1>iable<\/font> alistone) the object of this HTML <i>a<\/i> tag in the external Javascript&#8217;s list of HTML <i>a<\/i> tag elements it derived via &#8230;<\/p>\n<p><code><br \/>\nalist=document.getElementsByTagName('a');<br \/>\n<\/code><\/p>\n<p>We like what happens next.  We are mostly familiar with an HTML <i>a<\/i> tag having the <i>href<\/i> property be a navigation destination, or then perhaps extra functionality that gets executed with the <i>onclick<\/i> event.  Well, we don&#8217;t want to meddle with whatever happens with this &#8230; remember our <i>independently minded<\/i> external Javascript?  Well, we only ask that the parent doesn&#8217;t also define any functionality for the <i>onmousedown<\/i> event, which we want to &#8220;purloin&#8221; (is that the word?) into action for us.  Here&#8217;s our definition of what to do with that dot (yes, <u>.<\/u>) HTML <i>a<\/i> element&#8217;s <i>onmousedown<\/i> event &#8230;<\/p>\n<p><code><br \/>\n            alist[alistone].addEventListener('mousedown', function(event) {<br \/>\n               var xt=document.getElementById('xtranslate');<br \/>\n               var xh=document.getElementById('xhear');<br \/>\n               if (xt && xh && alistone &gt;= 0) {<br \/>\n                 var thishref=alist[alistone].href;<br \/>\n                 var thishparts=thishref.split('\/');<br \/>\n                 if (thishparts.length &gt;= 2) {<br \/>\n                  var thewordsare=thishparts[eval(-1 + thishparts.length)].replace(\/\\+\/g, '%20');<br \/>\n                  if (xt.checked && lto.replace('en','') != '') {<br \/>\n                   urlone='https:\/\/transl' + 'ate.google.com\/#' + lfrom + '\/' + lto + '\/' + thewordsare; \/\/, '_blank', 'top=30,left=30,width=300,height=300');<br \/>\n                   setTimeout(inawhileone, 2100);<br \/>\n                  }<br \/>\n                  if (xh.checked && lto != '') {<br \/>\n                   urltwo='https:\/\/tra' + 'nslate.google.com\/translate_tts?tl=' + lto + '&q=' + thewordsare; \/\/, '_blank', 'top=30,left=330,width=300,height=300');<br \/>\n                   setTimeout(inawhiletwo, 2300);<br \/>\n                  }<br \/>\n                 }<br \/>\n               }<br \/>\n             }, false);<br \/>\n<\/code><\/p>\n<p> &#8230; where the <i>xtranslate<\/i> and <i>xhear<\/i> ID&#8217;ed elements are (HTML type=)checkboxes for user defined <i>Translate<\/i> and <i>Hear<\/i> optional extra active functionality decisions, with reference to global var<font size=1>iable<\/font> <i>lto<\/i> which contains the Google Translate language code for the destination language of the user&#8217;s choice (from a dropdown list, the contents of which we frequently use through the www.rjmprogramming.com.au domain).<\/p>\n<p>So we must thank Google for their great <a target=_blank title='Google Translate' href='http:\/\/translate.google.com'>Google Translate<\/a> product, but, again, caution the user into thinking such translations are always sensibly &#8220;translatable&#8221; between languages.  Again, we stress, this new functionality should just be an aid to the desperate ESL student with little idea about some English presented to them.<\/p>\n<p>Again, we make use of Javascript <a target=_blank title='Javascript setTimeout information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_settimeout.asp'><i>setTimeout<\/i><\/a> &#8220;scheduled&#8221; Javascript function controller mechanism.  We find it endlessly useful, especially with events in ever changing platform environments.<\/p>\n<p>And so the two pieces of HTML and Javascript affected are &#8230;<\/p>\n<ol>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\" title=\"English Expression and Idiom Game\">Game<\/a> you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html-GETME\" title='englishexpressions_chalkboard.html'>englishexpressions_chalkboard.html<\/a> (changed in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html-GETME\" title='englishexpressions_chalkboard.html'>this way<\/a>) uses HTML and Javascript programming languages with this <a target=_blank title=\"live run\" href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\">live run<\/a> link<\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/phrasalverbs_chalkboard.html\" title=\"English Expression and Idiom Game\">Game<\/a> you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/phrasalverbs_chalkboard.html-GETME\" title='phrasalverbs_chalkboard.html'>phrasalverbs_chalkboard.html<\/a> (changed in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/phrasalverbs_chalkboard.html-GETME\" title='phrasalverbs_chalkboard.html'>this way<\/a>) uses HTML and Javascript programming languages with this <a target=_blank title=\"live run\" href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/phrasalverbs_chalkboard.html\">live run<\/a> link<\/li>\n<\/ol>\n<p> &#8230; both calling our new external Javascript you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/translate_hear.js_GETME\" title=\"translate_hear.js\">translate_hear.js<\/a> with new optional <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressionschalkboard.jpg\">functionality<\/a> <i>Translate<\/i> and\/or <i>Hear<\/i> some baffling English in an ESL student&#8217;s native tongue, perhaps.<\/p>\n<hr>\n<p id='eeaigpt'>Previous relevant <a target=_blank title='English Expressions and Idioms Game Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/english-expressions-and-idioms-game-primer-tutorial\/'>English Expressions and Idioms Game Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"English Expressions and Idioms Game Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.jpg\" title=\"English Expressions and Idioms Game Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">English Expressions and Idioms Game Primer Tutorial<\/p><\/div>\n<p>Advanced <a target=_blank title='ESL information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/English_as_a_second_or_foreign_language'>ESL<\/a> students are on the lookout for ways to &#8220;turbo charge&#8221; their improvement of English by being able to understand some of the English Expressions and <a target=_blank title='Idiom information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Idiom'>Idioms<\/a> an English native speaker is quite likely to take for granted &#8230; and so, alas, for the ESL beginner, is quite likely to slip into their conversational English.<\/p>\n<p>Today we present a missing part of one of these English Expressions or Idioms and get the user to try to fill in the missing part.<\/p>\n<p>Today we&#8217;d like to thank <a target=_blank title='Useful link' href='http:\/\/www.smart-words.org\/quotes-sayings\/idioms-meaning.html'>this link<\/a> for a great list of English expressions and idioms (thanks for the list and you can find an explanation of the meanings at this link too) and, as per usual with ESL games (here at this blog), <a target=_blank title='Free Dictionary' href='http:\/\/www.thefreedictionary.com'>The Free Dictionary<\/a> for the English expression or idiom lookups that may help linked off the underlined dot.  Also of great help was the advice regarding Linear Gradient backgrounds for our HTML5 canvas element used today, that came from this very very <a target=_blank title='Useful link regarding addColorStop canvas element from w3schools' href='http:\/\/www.w3schools.com\/tags\/canvas_addcolorstop.asp'>useful link<\/a>.<\/p>\n<p>This <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\" title=\"English Expression and Idiom Game\">game<\/a> you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html_GETME\" title='englishexpressions_chalkboard.html'>englishexpressions_chalkboard.html<\/a> uses HTML and Javascript programming languages.  Hopefully you can figure the rules when you click the picture above for a <a target=_blank title=\"live run\" href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/englishexpressions_chalkboard.html\">live run<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d20537' onclick='var dv=document.getElementById(\"d20537\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/esl\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20537' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d20578' onclick='var dv=document.getElementById(\"d20578\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20578' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A couple of our recent ESL tutorials regarding Phrasal Verbs (English Phrasal Verb Game Primer Tutorial) and English Expressions and Idioms (as with English Expressions and Idioms Game Primer Tutorial below) have a lot in common, especially their capacity to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/google-translate-english-phrasal-verbs-and-idioms-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,13,14,37],"tags":[184,281,396,1820,476,477,513,532,576,1821,652,939,997,1319],"class_list":["post-20578","post","type-post","status-publish","format-standard","hentry","category-elearning","category-esl","category-event-driven-programming","category-tutorials","tag-canvas","tag-css","tag-esl","tag-expression","tag-game","tag-games-2","tag-google","tag-google-translate","tag-html","tag-idiom","tag-javascript","tag-phrase","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20578"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=20578"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20578\/revisions"}],"predecessor-version":[{"id":20604,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20578\/revisions\/20604"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=20578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=20578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=20578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}