Skip to content

Instantly share code, notes, and snippets.

@buren
Created March 23, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buren/0395e629e02c540b5030 to your computer and use it in GitHub Desktop.
Save buren/0395e629e02c540b5030 to your computer and use it in GitHub Desktop.
and convert languages from Wikimedia to CSV
// Extract and convert languages @ below URL to CSV
// https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
var langCode = [];
$('.wikitable tbody tr td:nth-child(1)').each(function(){
langCode.push($(this).text());
});
var enName = [];
$('.wikitable tbody tr td:nth-child(2)').each(function(){
enName.push($(this).text());
});
var direction = [];
$('.wikitable tbody tr td:nth-child(3)').each(function(){
direction.push($(this).text());
});
var localName = [];
$('.wikitable tbody tr td:nth-child(4)').each(function(){
localName.push($(this).text());
});
var matrix = [];
for (var i = 0; i < langCode.length; i++) {
matrix.push([
langCode[i],
enName[i],
direction[i],
localName[i]
]);
}
var csvContent = '';
var dataString = '';
matrix.forEach(function(infoArray, index){
dataString = infoArray.join(',');
csvContent += index < matrix.length ? dataString + "\n" : dataString;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment