Google Translate Landing Page Changed Interfacing Links Tutorial
Onto yesterday’s Google Translate Landing Page Changed Interfacing Tutorial we wanted to extend the functionality, given user intervention, that other links on the Landing Pages can be sent to Google Translate for webpage translation.
We decided to …
Add two new global variables … |
var uprefix='';
var usuffix='';
|
For two iframes add id attribute … |
<div id=divtagcloud><iframe id=ifdtc style='display:none;' onerror='anticheckd(this);' onload='checkd(this);' src='//www.rjmprogramming.com.au/PHP/divtagcloud.html'></iframe></div>
<iframe id=ifzero onload="noandmaybe(this);" src="PHP/zero.html" title="Recent Blog Posts" style="width:264px;"></iframe>
|
Change function ChangeLCodeNow … |
function ChangeLcodeNow(){
//<![CDATA[
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1) && val.value != val.value.trim()) {
usuffix=usuffix.split('&obsolete=')[0];
document.getElementById('ifzero').src+='?random=' + Math.floor(Math.random() * 198767543); //alert(usuffix);
if (document.getElementById('divtagcloud') && !document.getElementById('ifdtc')) {
document.getElementById('divtagcloud').innerHTML="<iframe id=ifdtc style='display:none;' onerror='anticheckd(this);' onload='checkd(this);' src='PHP/divtagcloud.html?random=" + Math.floor(Math.random() * 198767543) + "'></iframe>";
} else {
document.getElementById('ifdtc').src+='?random=' + Math.floor(Math.random() * 198767543); //alert(usuffix);
}
} else if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var srectis=val.getBoundingClientRect();
var pprefix = val[val.selectedIndex].id;
var dd=new Date();
var wdg=val[val.selectedIndex].innerHTML;
uprefix='https://www-rjmprogramming-com-au.translate.goog';
usuffix='?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value.trim() + '&_x_tr_pto=wapp&obsolete=y';
if (1 == 1) {
//alert('<span style="position:absolute;top:' + srectis.top + 'px;left:' + srectis.left + 'px;">' + val[val.selectedIndex].innerHTML + ' <input type=checkbox onchange="usuffix=usuffix.split(' + "'" + '&obsolete=' + "'" + ')[0];"></input> Everywhere </span>');
if (1 == 2) {
document.body.innerHTML=document.body.innerHTML.replace(val.outerHTML, '<span style="z-index:123;position:absolute;top:' + srectis.top + 'px;left:' + srectis.left + 'px;">' + val[val.selectedIndex].innerHTML + ' <input type=checkbox onchange="usuffix=usuffix.split(' + "'" + '&obsolete=' + "'" + ')[0];"></input> Everywhere </span>');
} else {
document.getElementById('language').innerHTML='<option value="' + val.value.trim() + '" selected>' + wdg + '</option><option value="' + val.value.trim() + ' ">' + wdg + ' (everywhere)</option>';
document.getElementById('language').size='2';
}
window.open('https://www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value + '&_x_tr_pto=wapp', '_blank');
} else {
window.open('https://www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value + '&_x_tr_pto=wapp', '_blank');
document.getElementById('langone').innerHTML=val[val.selectedIndex].innerHTML + ' (and reclick for other translations)';
document.getElementById('langone').title=document.getElementById('langone').innerHTML;
val.title=document.getElementById('langone').innerHTML;
document.getElementById('langone').onclick = function(evt) { usuffix=usuffix.split('&obsolete=')[0]; this.innerHTML=this.innerHTML.split('(')[0] + '(everywhere)'; };
val.value='';
}
}
//]]>
}
|
Change function mwo … |
function mwo(in_url) {
// https://www.rjmprogramming.com.au/ITblog/css-countdown-reveal-tutorial/?pp&pn&title=CSS_Countdown_Reveal_Tutorial
//alert(in_url);
if (in_url.indexOf('&title=') != -1 && in_url.indexOf('?p=') != -1 && in_url.indexOf('rjmprogramming.com.au/') != -1) {
var tis=in_url.split('&title=')[1].split('&')[0].split('#')[0].replace(/\_/g,'-').toLowerCase();
var ptis=in_url.split('?p=')[1].split('&')[0].split('#')[0];
if (isiPad || isiPhone || isiPod || isAndroid) {
if (usuffix != '' && usuffix.indexOf('&obsolete=') == -1) {
var inurl=in_url.split('?')[0] + in_url.split('&title=')[1].toLowerCase().replace(/\_/g,'-');
//alert(inurl);
return inurl.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix;
//return (in_url.split('rjmprogramming.com.au/')[0] + 'rjmprogramming.com.au/ITblog/' + tis).replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix + '#post-' + ptis + '#andabit=-70';
//} else if (usuffix != '' && usuffix.indexOf('&obsolete=') != -1) {
//var inurl=in_url.split('?')[0] + in_url.split('&title=')[0].toLowerCase().replace(/\_/g,'-');
//return inurl.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix;
} else {
return in_url.split('rjmprogramming.com.au/')[0] + 'rjmprogramming.com.au/ITblog/' + tis + '#post-' + ptis + '#andabit=-70';
}
} else if (usuffix != '' && usuffix.indexOf('&obsolete=') == -1) {
var inurl=in_url.split('?')[0] + in_url.split('&title=')[1].toLowerCase().replace(/\_/g,'-');
//alert(inurl);
return inurl.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix;
//return (in_url.split('rjmprogramming.com.au/')[0] + 'rjmprogramming.com.au/ITblog/' + tis).replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix; // + '#post-' + ptis;
} else {
return in_url.split('rjmprogramming.com.au/')[0] + 'rjmprogramming.com.au/ITblog/' + tis; // + '#post-' + ptis;
}
} else if (usuffix != '' && usuffix.indexOf('&obsolete=') != -1) {
return in_url.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix;
} else {
return in_url;
}
}
|
Change function windowopen … |
function windowopen(myurl,mytarget) {
if (isiPad || isiPhone || isiPod) {
var aobod = document.getElementById('abod');
aobod.href=mwo(myurl);
aobod.click();
} else if (isAndroid) {
top.window.open(mwo(myurl),mytarget);
} else if (usuffix.indexOf('&obsolete=') == -1 && usuffix != '') {
top.window.open(mwo(myurl),mytarget);
} else {
top.window.open(myurl,mytarget);
//location.href=myurl;
}
}
|
For two iframes change onload event functionalities … |
function checkd(iois) {
if (iois != null) {
var aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null) {
if (usuffix != '' && usuffix.indexOf('&obsolete=') == -1) {
var wasabi=aconto.body.innerHTML;
var qps=wasabi.split('?p=');
var iqps=0;
var insr='';
qps=wasabi.split(' href="');
for (iqps=1; iqps<qps.length; iqps++) {
insr=qps[iqps].split('"')[0];
wasabi=wasabi.replace(insr, insr.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix);
}
aconto.body.innerHTML=wasabi;
if (divtc != '') { divtc=wasabi; }
} else {
divtc=aconto.body.innerHTML;
}
if (divtc.indexOf(' class="tagcloud"') != -1) {
setTimeout(divtctoggler, 8000);
} else {
document.getElementById('divtagcloud').innerHTML='';
}
}
}
}
}
function noandmaybe(iois) {
var aconto=null, jps=[];
if ((usuffix != '' && usuffix.indexOf('&obsolete=') == -1) || !navigator.userAgent.match(/Android|BlackBerry|iPhone|iPod|Opera Mini|IEMobile/i)) { // or it is not a mobile device
if (iois != null) {
aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null) {
aconto.body.innerHTML=aconto.body.innerHTML.replace(/\#andabit\=\-70/g,'');
}
if (usuffix != '' && usuffix.indexOf('&obsolete=') == -1) {
var wasabi=aconto.body.innerHTML;
var qps=wasabi.split('?p=');
var iqps=0;
var insr='';
for (iqps=1; iqps<qps.length; iqps++) {
wasabi=wasabi.replace('?p=' + qps[iqps].split('"')[0], qps[iqps].split(' alt="')[1].split('"')[0].toLowerCase().replace("+","").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(/---/g,"-").replace(/--/g,"-") + '/');
}
qps=wasabi.split(' href="');
for (iqps=1; iqps<qps.length; iqps++) {
insr=qps[iqps].split('"')[0];
wasabi=wasabi.replace(insr, insr.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix);
}
aconto.body.innerHTML=wasabi;
for (iqps=1; iqps<=5; iqps++) {
insr=document.getElementById('adiv' + iqps).outerHTML;
wasabi=insr.replace('?p=' + insr.split('?p=')[1].split('"')[0], insr.split(' title="')[1].split('"')[0].toLowerCase().replace("+","").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace("/","").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(" ","-").replace(/---/g,"-").replace(/--/g,"-") + '/');
document.getElementById('adiv' + iqps).href=wasabi.split(' href="')[1].split('"')[0].replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix;
}
var asis=document.getElementsByTagName('a');
for (iqps=0; iqps<asis.length; iqps++) {
if (('' + asis[iqps].href).toLowerCase().indexOf('rjmprogramming.com.au') != -1) {
asis[iqps].href=(asis[iqps].href.replace('http://www.rjmprogramming.com.au', uprefix).replace('https://www.rjmprogramming.com.au', uprefix).replace('//www.rjmprogramming.com.au', uprefix).replace('http://rjmprogramming.com.au', uprefix).replace('https://rjmprogramming.com.au', uprefix).replace('//rjmprogramming.com.au', uprefix).split('#')[0].split('?')[0] + usuffix).replace('/wordpress/','/ITblog/');
}
}
}
}
}
}
if (document.getElementById('style_3') && ('' + document.getElementById('style_3').title) == '') {
if (!aconto) {
aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
}
}
var omover=' onmouseover="omright(this);" ', omout=' onmouseout="moright(this);" ', bdapp='<table id=tblr style=display:none><tr></tr></table>';
var rdbit='?rand=' + Math.floor(Math.random() * 1985676);
if (aconto) {
if (aconto.body != null) {
if (document.getElementById('p_style_3')) {
document.getElementById('style_3').innerHTML=document.getElementById('p_style_3').outerHTML.replace(/\.jpg/g, '.jpg' + rdbit);
}
var hrefs=aconto.body.innerHTML.split(' href=');
var style_3r=document.getElementById('style_3').getBoundingClientRect();
document.getElementById('style_3').title='Feel free to visit thumbnail links to our WordPress Tutorial blog!';
for (var ihrefs=1; ihrefs<hrefs.length; ihrefs++) {
//document.body.innerHTML+='<div id=ediv' + ihrefs + '></div>';
bdapp=bdapp.replace('</tr>', '<td id=ediv' + ihrefs + '></td></tr>');
jps=hrefs[ihrefs].split('.jpeg?rand=');
console.log(jps[0].slice(-9));
if (jps[0].slice(-3).indexOf('-') != -1) { jps[0]=jps[0].split('-')[eval(-2 + eval('' + jps[0].split('-').length))]; }
switch (jps[0].slice(-3)) {
case 'ght':
document.body.innerHTML+='<a id=adiv5' + omover + omout + ' target=_blank style="opacity:0.5;background-repeat:no-repeat;background-size:30px 20px;background-image:url(/PHP/eight.jpg' + rdbit + ');position:absolute;z-index:99;top:' + style_3r.top + 'px;width:30px;height:20px;background-color:transparent;left:' + style_3r.left + 'px;" title="' + hrefs[ihrefs].substring(1).split(' title=')[1].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '" href="' + hrefs[ihrefs].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '"></a>';
break;
case 'ven':
document.body.innerHTML+='<a id=adiv4' + omover + omout + ' target=_blank style="opacity:0.5;background-repeat:no-repeat;background-size:30px 20px;background-image:url(/PHP/seven.jpg' + rdbit + ');position:absolute;z-index:99;top:' + style_3r.top + 'px;width:30px;height:20px;background-color:transparent;left:' + eval(eval(eval(style_3r.left + style_3r.right) / 2) - 15) + 'px;" title="' + hrefs[ihrefs].substring(1).split(' title=')[1].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '" href="' + hrefs[ihrefs].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '"></a>';
break;
case 'six':
document.body.innerHTML+='<a id=adiv3' + omover + omout + ' target=_blank style="opacity:0.5;background-repeat:no-repeat;background-size:30px 20px;background-image:url(/PHP/six.jpg' + rdbit + ');position:absolute;z-index:99;top:' + style_3r.top + 'px;width:30px;height:20px;background-color:transparent;left:' + eval(style_3r.right - 30) + 'px;" title="' + hrefs[ihrefs].substring(1).split(' title=')[1].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '" href="' + hrefs[ihrefs].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '"></a>';
break;
case 'ive':
document.body.innerHTML+='<a id=adiv2' + omover + omout + ' target=_blank style="opacity:0.5;background-repeat:no-repeat;background-size:30px 20px;background-image:url(/PHP/five.jpg' + rdbit + ');position:absolute;z-index:99;top:' + eval(style_3r.bottom - 20) + 'px;width:30px;height:20px;background-color:transparent;left:' + style_3r.left + 'px;" title="' + hrefs[ihrefs].substring(1).split(' title=')[1].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '" href="' + hrefs[ihrefs].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '"></a>';
break;
case 'our':
document.body.innerHTML+='<a id=adiv1' + omover + omout + ' target=_blank style="opacity:0.5;background-repeat:no-repeat;background-size:30px 20px;background-image:url(/PHP/four.jpg' + rdbit + ');position:absolute;z-index:99;top:' + eval(style_3r.bottom - 20) + 'px;width:30px;height:20px;background-color:transparent;left:' + eval(style_3r.right - 30) + 'px;" title="' + hrefs[ihrefs].substring(1).split(' title=')[1].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '" href="' + hrefs[ihrefs].substring(1).split(hrefs[ihrefs].substring(0,1))[0] + '"></a>';
break;
default:
break;
}
}
document.body.innerHTML+=bdapp;
bodyrect=document.getElementById('nav_layer').getBoundingClientRect();
}
}
}
}
|
Feel free to try, coming off a new “(everywhere)” appended dropdown option a user can select!
Previous relevant Google Translate Landing Page Changed Interfacing Tutorial is shown below.
Google Translate Landing Page Changed Interfacing Tutorial
It pays to keep in touch with third party arrangements you have in place, as for the recent Google Translate Landing Page Translate Updated List Tutorial‘s interfacing to the great Google Translate resource capable of translating our RJM Programming blog (via Landing page language dropdown (select) element up the top right) to non-English languages.
But two interfacing to Google Translate aspects have changed since we had occasion to “see how this was going” (oops!) …
- enforcing https: protocol … and …
- extra &_x_tr_pto=wapp to arguments … as per old versus new Landing Page Javascript code arrangements …
function oldChangeLcodeNow(){
//<![CDATA[
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var pprefix = val[val.selectedIndex].id;
var dd=new Date();
window.open('//www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value, '_blank');
}
//]]>
}
function ChangeLcodeNow(){
//<![CDATA[
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var pprefix = val[val.selectedIndex].id;
var dd=new Date();
window.open('https://www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value + '&_x_tr_pto=wapp', '_blank');
}
//]]>
}
… linking the user picking a non-English language off the dropdown element be able to translate that day’s latest RJM Programming blog post into that language via Google Translate. Thanks heaps!
Previous relevant Google Translate Landing Page Translate Updated List Tutorial is shown below.
Google Translate Landing Page Translate Updated List Tutorial
Yesterday’s Google Translate Landing Page Translate Update Tutorial left off with …
It’s the start that does not ingrain the webpage HTML to any great permanence, and that is for another “PHP involvement” day.
… and that new day is upon us. Whenever you combine …
- PHP writing public HTML webpage data … with …
- a user interface (and we’d really only like that “user set” to be an administrator of this blog)
… it’s a potential data security issue you are opening up, and yet, we do want to involve some automation of webpage code here for something that can be ascertained. So let’s try to protect ourselves (to some degree) regarding the PHP below …
<?php
if (isset($_POST['langih']) && strpos(strtolower('' . $_SERVER['HTTP_REFERER']), "rjmprogramming.com.au/about_us.html") !== false) {
$prefis="./";
$ftf=["index.htm","index.html","indexmobile.html","About_Us.html","Contact_Us.html","Guestbook.html","Link.html","Links.html","Services.html","Welcome.html","News.html","Welcome.htm","Welcomeslideshow.htm","Welcomeslideshow.html","slideshow.html"];
$lih=str_replace("+", " ", urldecode($_POST['langih']));
if (strpos("~" . strtolower($lih), "~<option") !== false) {
if (strpos(strtolower($lih) . "~", "</option>~") !== false) {
if (strpos($lih, ">Blog Language") !== false) {
for ($i=0; $i<sizeof($ftf); $i++) {
if (file_exists($prefis . $ftf[$i])) {
$cont=file_get_contents($prefis . $ftf[$i]);
if (strpos($cont, ">Blog Language") !== false) {
if (strpos(str_replace("<option","",str_replace("</option>","",strtolower($lih))), "<") === false) {
if (strlen(explode("</select>", explode(">Blog Language", $lih)[1])[0]) > strlen($wasis)) {
if (sizeof(explode(">",explode("</select>", explode(">Blog Language", $lih)[1])[0])) >= sizeof(explode(">",$wasis))) {
file_put_contents($prefis . $ftf[$i] . "_spare", $cont);
$wasis=explode("</select>", explode(">Blog Language", $cont)[1])[0];
$contnew=str_replace($wasis, explode("</select>", explode(">Blog Language", $lih)[1])[0], $cont);
file_put_contents($prefis . $ftf[$i], $contnew);
}
}
}
}
}
}
}
}
}
}
exit;
?>
… restricting calling URLs and some of the look and size and content of the posted data, and working with the “About Us” webpage “place” to automate, the idea of choosing “English” from the “Blog Language” dropdown, as per the changed Javascript and Ajax “way in” …
function ChangeLcodeNow(){
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var pprefix = val[val.selectedIndex].id;
var dd=new Date();
window.open('//www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value, '_blank');
} else if (val.value.length != 0 && val.value.indexOf('en') != (0 - 1)) {
if (ajaxitp) { ajaxitp(); }
}
}
function ajaxitp() {
var xurl = './getme.php';
var formis = new FormData();
myxhr = new XMLHttpRequest();
if (myxhr) {
formis.append('langih', document.getElementById('language').innerHTML);
myxhr.open('POST', xurl); //, true);
myxhr.send(formis);
}
}
Previous relevant Google Translate Landing Page Translate Update Tutorial is shown below.
Google Translate Landing Page Translate Update Tutorial
The recent Google Translate Landing Page Translate Tutorial …
… and so, we are here today, with our start to remedies for this (Javascript DOM, via Ajax, change below) …
var myxhr=null;
function backin() {
if (myxhr.readyState == 4) {
if (myxhr.status == 200) {
if (myxhr.responseText) {
if (document.getElementById('language')) {
//alert(myxhr.responseText);
var mhs=myxhr.responseText.replace(/\<\/code\>\<\/td\>/g,'<>').split('><code translate="no" dir="ltr">');
if (mhs.length > 1) {
var thiscodeis='', thisdescis='';
var wasih=document.getElementById('language').innerHTML;
var outih=wasih.split('</option>')[0] + '</option>';
var origih=wasih.replace(outih, '');
for (var iuh=1; iuh<mhs.length; iuh++) {
thisdescis=mhs[eval(-1 + iuh)].split('<td>')[eval(-1 + mhs[eval(-1 + iuh)].split('<td>').length)];
//console.log('first thisdescis=' + thisdescis + ' and mhs[eval(-1 + iuh)]=' + mhs[eval(-1 + iuh)].slice(-200));
thisdescis=thisdescis.split('<')[0];
thiscodeis=mhs[iuh].split('<')[0].split('(')[0].trim();
//console.log('thiscodeis=' + thiscodeis + ' and thisdescis=' + thisdescis + ' and mhs[eval(-1 + iuh)]=' + mhs[eval(-1 + iuh)].slice(-200));
if (wasih.toLowerCase().indexOf(' value="' + thiscodeis.toLowerCase() + '"') == -1 && wasih.toLowerCase().indexOf(thisdescis.toLowerCase()) == -1) {
outih+='<option value="' + thiscodeis + '">' + thisdescis + ' ✨</OPTION>';
} else {
outih+='<option value="' + thiscodeis + '">' + thisdescis + '</OPTION>';
}
}
if (outih.indexOf('/OPTION') != -1 && origih.toLowerCase() != outih.toLowerCase()) {
document.getElementById('language').innerHTML=outih.replace('</option>', ' ✨</OPTION>');
document.getElementById('language').style.maxWidth='150px';
}
}
}
}
}
}
}
function ajaxit() {
var xurl = '//cloud.google.com/translate/docs/languages';
//alert(1);
myxhr = new XMLHttpRequest();
if (myxhr) {
//alert(2);
myxhr.onreadystatechange = backin;
myxhr.open('GET', 'getme.php?getme=' + encodeURIComponent(xurl), true);
myxhr.send(null);
}
}
function refreshl() {
if (document.getElementById('language')) {
ajaxit();
}
}
setTimeout(refreshl, 5000);
It’s the start that does not ingrain the webpage HTML to any great permanence, and that is for another “PHP involvement” day.
Previous relevant Google Translate Landing Page Translate Tutorial is shown below.
Google Translate Landing Page Translate Tutorial
Yesterday’s …
- Google Translate Webpage Translate Tutorial was the major part of RJM Programming’s Google Translate strategy change (ie. getting it working again … doh!) … but it’s not the whole story … and another part is …
- today we extend that strategy to change the RJM Programming Landing Page Google Translate interfacing to change from a “Landing Page content” strategy to a “Navigate to WordPress Blog” strategy (feeding into yesterday’s thinking), our justification being that the better content of the RJM Programming domain sits within the WordPress Blog we support and maintain
… so there, ngarrrrgh!
But (growing up quickly) we see a better arrangement here, just adding the prefix “Blog” onto the old (just) “Language” labelled dropdown to modify the “new “Blog Language” (to end up with HTML snippet <option value=””>Blog Language</option>) dropdown’s Javascript “onchange” event logic …
// To ...
function ChangeLcodeNow(){
//<![CDATA[
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var pprefix = val[val.selectedIndex].id;
var dd=new Date();
window.open('//www-rjmprogramming-com-au.translate.goog/ITblog/' + dd.getFullYear() + '/' + ('0' + eval(1 + eval('' + dd.getMonth()))).slice(-2) + '/' + ('0' + eval(0 + eval('' + dd.getDate()))).slice(-2) + '/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value, '_blank');
}
//]]>
}
// ... From ...
function olderChangeLcodeNow(){
//<![CDATA[
var val = document.getElementById('language');
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
var pprefix = val[val.selectedIndex].id;
windowopen('http://translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Findex.html&tl=' + val.value, '_blank');
}
//]]>
}
Again, not too onerous!
Previous relevant Google Translate Webpage Translate Tutorial is shown below.
Google Translate Webpage Translate Tutorial
We really like the way Google Translate can language translate whole webpages for URLs of choice, sometimes. We use it here at this blog, but sometime into the past … we cannot recall (sorrrrrryyyyyyyyy!) … the arrangements of use of this great functionality changed, and today we want to go over what we did for this blog to fix some of this interfacing.
It was in good ol’ WordPress TwentyTen theme’s header.php we made the change to facilitate this “reconnection” to this great functionality …
<?php
function ChangeLcodeNow(){
var val = document.getElementById('language');
//alert(val.value);
if (val.value.length != 0 && val.value.indexOf('en') == (0 - 1)) {
//alert(val.value);
var pprefix = val[val.selectedIndex].id;
<?php
$p316 = "316";
$pprefix = "";
if (strpos($_SERVER['QUERY_STRING'], "p=0") !== false) {
$pprefix = "";
} else {
if (isset($_GET['p'])) {
if (strpos($_GET['p'], "304") !== false) {
$p316 = "316";
} else {
$p316 = $_GET['p'];
}
}
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if ($isiPad === false) {
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone');
}
if ($isiPad === false) {
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android');
}
if (1 == 1) { // _x_tr_sl=en&_x_tr_tl=de&_x_tr_hl=en-GB&_x_tr_pto=nui
echo " window.open('//www-rjmprogramming-com-au.translate.goog/ITblog?p=' + pprefix + '&_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=' + val.value, '_top'); " . "\n";
} else {
if ($isiPad) {
//echo " window.open('//translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Fwordpress%2F%3Fp%3D' + pprefix + '".$p316."&tl=' + val.value, '_top'); " . "\n";
echo " window.open('//translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Fwordpress%2F%3Fp%3D' + pprefix + '".$p316."&tl=' + val.value, '_top'); " . "\n";
} else {
//echo "window.location.href = '//translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Fwordpress%2F%3Fp%3D' + pprefix + '".$p316."&tl=' + val.value; " . "\n";
echo "window.location.href = '//translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Fwordpress%2F%3Fp%3D' + pprefix + '".$p316."&tl=' + val.value; " . "\n";
}
}
}
?>
//window.open('//translate.google.com/translate?sl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.rjmprogramming.com.au%2Fwordpress&tl=' + val.value, '_blank');
//alert("yes" + val.value);
}
}
?>
Not too bruising!
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.