Country Data Conduits Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Country Data Conduits Tutorial

Country Data Conduits Tutorial

The data flows surrounding the use of โ€œcow.txtโ€ in yesterdayโ€™s Country Data Google Translate Tutorial take a variety of forms โ€ฆ

  • country data is selected via dropdowns, so we have arranged those dropdowns to contain a variety of global data attributes โ€ฆ
    1. data-mapurl โ€ฆ is populated with a Google Chart Map Chart URL (derived via fields in โ€œcow.txtโ€)
    2. data-geourl โ€ฆ is populated with a Google Chart Geo Chart URL (derived via fields in โ€œcow.txtโ€)
    3. data-langlist โ€ฆ is populated with country Language Code list (as a field in โ€œcow.txtโ€)
    4. data-it โ€ฆ helps us link Country Names with Country Codes (derived from โ€œcow.txtโ€)
    5. whole series of data-capital prefixing global data attributes describing Capital City Names in a variety of languages (directly from โ€œcow.txtโ€ fields)

    โ€ฆ and today those dropdowns are also given a โ€ฆ

  • title attribute โ€ฆ
    1. containing Population and Population Year and Area (out of โ€œcow.txtโ€) and Population Density we calculate โ€ฆ that โ€ฆ
    2. at least for non-mobile platforms this information above will display when hovering over the dropdowns

โ€ฆ which begs the question โ€ฆ



For a dropdown onchange event (passing in this to variable iso) how could you reference global data attribute data-mapurl for example?

โ€ฆ try โ€ฆ



var theurlformapchartis = iso.options[iso.selectedIndex].getAttribute('data-mapurl');

โ€ฆ showing you how lots of the dynamics of the web application can launch themselves from dropdown onchange event Javascript functions.

Bit like XML for (albeit kludgy) data usefulness, donโ€™t you think?

Yet again, try this, in thechanged country_dataโšซhtml Country Data web application start below, that, now, may navigate you to โ€œthehow we got thereโ€ PHPโšชcode Google Translate friendly version for your perusal.



Previous relevant Country Data Google Translate Tutorial is shown below.

Country Data Google Translate Tutorial

Country Data Google Translate Tutorial

The โ€ฆ

  • โ€œcow.txtโ€ in an HTML iframe arrangement
  • limits to Google Translate timings related to Javascript DOM (element populating in particular) can result in half done translations

โ€ฆ within yesterdayโ€™s Country Data Geodata Tutorialโ€˜s web applicationโ€™s design has had us needing to involve PHP into the mix as we try to add โ€œcow.txtโ€ derived country language codes of interest into the Google Translate friendly thanks functionality of our recent and ongoing Country Data web application.

We get help from another language code lookup source, thanks, today, we allow for Language Code presentations that are not just a pretty unfriendly code, only.

Letโ€™s see an example of a Google Translate URL โ€ฆ



https://www-rjmprogramming-com-au.translate.goog/HTMLCSS/country_data/?_x_tr_sl=en&_x_tr_hl=en-GB&_x_tr_pto=nui&_x_tr_tl=ru&_x_tr_pto=wapp&data_cc=AR&amgt=y

โ€ฆ with the following characteristics โ€ฆ

  • an RJM Programming PHP URL equivalent is mapped to a Google Translate one โ€ฆ via โ€ฆ
    1. dot ( ie . ) parts of domain name are replaced by minus ( ie โ€“ )
    2. straight after domain name .translate.goog is placed
  • &_x_tr_tl= GET argument ( eg &_x_tr_tl=ru means translate from โ€œ?_x_tr_sl=enโ€ English to Russian )
  • &data_cc= GET argument is an inhouse construct (yes, you can append your own GET arguments and use a โ€œtop.location.hrefโ€ approach to updating a Google Translate URL ) ( eg &data_cc=AR means display โ€œcow.txtโ€ data relating to Country Code AR which is Argentina )

We use a special blank language code to revert back to an RJM Programming URL from a Google Translate URL using language code EN which is English. Otherwise, once within a Google Translate URL the user generally stays there.

This Google Translate approach does a much more thorough translation job of all the โ€œcow.txtโ€ derived data above the โ€œgeodataโ€ HTML mapping iframes, allowing โ€ฆ

  • Country names
  • Capital City names

โ€ฆ be translated into many languages that โ€œcow.txtโ€ is not designed to address.

Of particular importance, now, in the revised code, is the use made of the global HTML element attribute โ€œtranslateโ€ โ€ฆ

The translate attribute specifies whether the content of an element should be translated or not.

โ€ฆ and we use translate=โ€noโ€ for data โ€œcodeโ€ elements and translate=โ€yesโ€ for data โ€œdisplay text (of that code)โ€ elements, so as to Internationalize what this web application is capable of.

Again, try this, in thechanged country_dataโšซhtml Country Data web application start below, that, now, may navigate you to โ€œthehow we got thereโ€ PHPโšชcode Google Translate friendly version for your perusal.


Previous relevant Country Data Geodata Tutorial is shown below.

Country Data Geodata Tutorial

Country Data Geodata Tutorial

We started Country Data Primer Tutorialโ€˜s perusal of the โ€ฆ

great Open Licence data source concerning a country data โ€œcow.txtโ€ flat file with semicolon column separators, thanks to the heads up at this great link

โ€ฆ start to our endeavours without referencing โ€œgeodataโ€. But there is โ€œgeodataโ€ in โ€œcow.txtโ€, and so it behoves us to represent that in a โ€ฆ in a โ€ฆ anyone, anyone? Yes, Anaximander, son of Praxiades โ€ฆ or is that Praximander, son of Anaxiades โ€ฆ please, in future, can you separate or one of you take the town drain home โ€ฆ we can plot positions on a map.

How about one of Googleโ€™s Charts, such as โ€ฆ

โ€ฆ so that the user can see โ€œwhereโ€ in the world the Country (and its Capital) are located?

Try this, in thechanged country_dataโšซhtml Country Data web application start below.


Previous relevant Country Data Primer Tutorial is shown below.

Country Data Primer Tutorial

Country Data Primer Tutorial

The other day we came upon a great Open Licence data source concerning a country data โ€œcow.txtโ€ flat file with semicolon column separators, thanks to the heads up at this great link.

With todayโ€™s blog posting we start out writing a Javascript and HTML web application using โ€œcow.txtโ€ hosted in an HTML iframe element arrangement, and relying on its โ€œonloadโ€ event Javascript language โ€ฆ



function checkif(iois, four) {

var aconto = (iois.contentWindow || iois.contentDocument);

if (aconto != null) {

if (aconto.document) { aconto = aconto.document; }

if (aconto.body != null) {

if (origihcode == '') {

origihcode=document.getElementById('ccode').innerHTML;

origihname=document.getElementById('cname').innerHTML;

} else {

document.getElementById('ccode').innerHTML=origihcode;

document.getElementById('cname').innerHTML=origihname;

}

var cols=[];

var lines=aconto.body.innerText.split(String.fromCharCode(10));

document.getElementById('tdcapital').innerHTML='';

for (var i=0; i<lines.length; i++) {

cols=lines[i].split(';');

if (eval('' + lines[i].length) > 3 && eval('' + cols[0].length) == 2 && eval('' + cols.length) > eval('' + four)) {

if (prevval != '' && prevval.indexOf(orflag(cols[0])) != -1) {

var ihis='<option data-capital="' + cols[36].trim() + '" data-capital4="' + cols[36].trim() + '" data-capital8="' + cols[39].trim() + '" data-capital15="' + cols[40].trim() + '" data-capital17="' + cols[41].trim() + '" data-capital32="' + cols[42].trim() + '" data-capital29="' + cols[36].trim() + '" value="' + cols[0] + ' ' + orflag(cols[0]) + '" selected>' + (cols[eval('' + four)].trim() == '' ? cols[4] : cols[eval('' + four)]) + ' ' + orflag(cols[0]) + '</option>';

document.getElementById('cname').innerHTML+=ihis;

document.getElementById('ccode').innerHTML+='<option data-capital="' + cols[36].trim() + '" data-capital4="' + cols[36].trim() + '" data-capital8="' + cols[39].trim() + '" data-capital15="' + cols[40].trim() + '" data-capital17="' + cols[41].trim() + '" data-capital32="' + cols[42].trim() + '" data-capital29="' + cols[36].trim() + '" value="' + (cols[eval('' + four)].trim() == '' ? cols[4] : cols[eval('' + four)]) + ' ' + orflag(cols[0]) + '" selected>' + cols[0] + ' ' + orflag(cols[0]) + '</option>';

document.getElementById('tdcapital').innerHTML=(('' + ihis.split(' data-capital' + document.getElementById('lang').value + '="')[1].split('"')[0].trim()) == '' ? ('' + ihis.split(' data-capital' + '="')[1].split('"')[0].trim()) : ('' + ihis.split(' data-capital' + document.getElementById('lang').value + '="')[1].split('"')[0].trim()) );

} else {

document.getElementById('cname').innerHTML+='<option data-capital="' + cols[36].trim() + '" data-capital4="' + cols[36].trim() + '" data-capital8="' + cols[39].trim() + '" data-capital15="' + cols[40].trim() + '" data-capital17="' + cols[41].trim() + '" data-capital32="' + cols[42].trim() + '" data-capital29="' + cols[36].trim() + '" value="' + cols[0] + ' ' + orflag(cols[0]) + '">' + (cols[eval('' + four)].trim() == '' ? cols[4] : cols[eval('' + four)]) + ' ' + orflag(cols[0]) + '</option>';

document.getElementById('ccode').innerHTML+='<option data-capital="' + cols[36].trim() + '" data-capital4="' + cols[36].trim() + '" data-capital8="' + cols[39].trim() + '" data-capital15="' + cols[40].trim() + '" data-capital17="' + cols[41].trim() + '" data-capital32="' + cols[42].trim() + '" data-capital29="' + cols[36].trim() + '" value="' + (cols[eval('' + four)].trim() == '' ? cols[4] : cols[eval('' + four)]) + ' ' + orflag(cols[0]) + '">' + cols[0] + ' ' + orflag(cols[0]) + '</option>';

}

}

}

}

}

prevval='';

}

โ€ฆ that dovetails with HTML โ€ฆ



<iframe style=display:none; id=myif onload=checkif(this,document.getElementById('lang').value); src='/cow.txt'></iframe>

โ€ฆ and imagine weโ€™ll extend its functionality into the near future, onto its proof of concept country_dataโšซhtml Country Data web application start โ€ฆ

We hope you hang about for the ride?!

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.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *