Created
July 26, 2014 15:01
-
-
Save AshKyd/6c0cef0ebe03a1847408 to your computer and use it in GitHub Desktop.
Create a list of countries and languages spoken from the "List of official languages by state" page on Wikipedia https://en.wikipedia.org/wiki/List_of_official_languages_by_state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var countries = []; | |
// These states have no official languages, so override them with these ones. | |
var override = { | |
"United Kingdom": ['English'], | |
"United States": ['English'], | |
"Australia": ['English'], | |
"Mexico": ['Spanish'], | |
"Chile": ['Spanish'], | |
} | |
function sanitiseName(name) { | |
return $.trim(name.match(/([^\(\[]*)/)[0]); | |
} | |
$('#mw-content-text > ul > li').each(function() { | |
var country = sanitiseName($('b:eq(0)', this).text()); | |
var languages = []; | |
if (override[country]) { | |
languages = override[country]; | |
} else { | |
$(this).find('>ul>li').each(function() { | |
languages.push(sanitiseName($(this).text())); | |
}); | |
} | |
countries.push({ | |
country: country, | |
languages: languages | |
}); | |
}); | |
console.log(JSON.stringify(countries)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment