function initializeLanguageSwitcher(returned_data){
  for(lang in returned_data.entities.Q5.labels) { //Q5 is arbitrary. Choose one that gets translated for sure.
    supported_languages.push(lang);
  }
  var langstr = supported_languages.join("|");

  var langstr_query =
    'SELECT ?lang ?langLabel ?abbr ' +
    'WHERE' +
    '{' +
      '?lang wdt:P218 ?abbr;' +
      'FILTER regex (?abbr, "^('+langstr+')$").' +
      'SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }' +
    '}';

  langstr_query = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=' +encodeURIComponent(langstr_query) + "&format=json";
  $.getJSON(langstr_query, function (langstrings){

    langstrings.results.bindings.forEach(function (item) {
      abbr_langnames[item.abbr.value] = item.langLabel.value;
      langnames_abbr[item.langLabel.value] = item.abbr.value;
      langnames.push(item.langLabel.value);
    });
    langnames.sort();

    resetLang();
    setFallbackLangs();

    $("#map-menu-container .top").append(
        "<div id=languageSelector onClick=\"$('#languageSelector ul').toggleClass('open');\">" +
          "<span lang=en>Choose Language:</span>" +
          "<ul></ul>" +
        "</div>");

    langnames.forEach(function (item) {
      var langcode = langnames_abbr[item];
      var is_default = (langcode == current_lang) ? " class=default" : "";
      console.log("adding lang '" + langcode + "' (" + item + ")");
      $("#languageSelector ul").append("<li targetlang=" + langcode + is_default + " onClick='switchToLang(\""+langcode+"\");'>"+item+"</li>");
    });
  });
}
/* get languages for UI from our Wikibase, and pick languages that are translated there */
get languages for UI from our Wikibase, and pick languages that are translated there
get languages for UI from our Wikibase and pick languages that are translated there
function initializeLanguageSwitcher(returned_data){
  for(lang in returned_data.entities.Q5.labels) { 
    supported_languages.push(lang);
  }
  var langstr = supported_languages.join("|");
  var langstr_query =
    'SELECT ?lang ?langLabel ?abbr ' +
    'WHERE' +
    '{' +
      '?lang wdt:P218 ?abbr;' +
      'FILTER regex (?abbr, "^('+langstr+')$").' +
      'SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }' +
    '}';
  langstr_query = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=' +encodeURIComponent(langstr_query) + "&format=json";
  $.getJSON(langstr_query, function (langstrings){
    langstrings.results.bindings.forEach(function (item) {
      abbr_langnames[item.abbr.value] = item.langLabel.value;
      langnames_abbr[item.langLabel.value] = item.abbr.value;
      langnames.push(item.langLabel.value);
    });
    langnames.sort();
    resetLang();
    setFallbackLangs();
    $("#map-menu-container .top").append(
        "<div id=languageSelector onClick=\"$('#languageSelector ul').toggleClass('open');\">" +
          "<span lang=en>Choose Language:</span>" +
          "<ul></ul>" +
        "</div>");
    langnames.forEach(function (item) {
      var langcode = langnames_abbr[item];
      var is_default = (langcode == current_lang) ? " class=default" : "";
      console.log("adding lang '" + langcode + "' (" + item + ")");
      $("#languageSelector ul").append("<li targetlang=" + langcode + is_default + " onClick='switchToLang(\""+langcode+"\");'>"+item+"</li>");
    });
  });
}
function initializeLanguageSwitcher ( returned_data ) { for ( lang in returned_data . entities . Q5 . labels ) { supported_languages . push ( lang ) ; } var langstr = supported_languages . join ( "|" ) ; var langstr_query = 'SELECT ?lang ?langLabel ?abbr ' + 'WHERE' + '{' + '?lang wdt:P218 ?abbr;' + 'FILTER regex (?abbr, "^(' + langstr + ')$").' + 'SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }' + '}' ; langstr_query = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=' + encodeURIComponent ( langstr_query ) + "&format=json" ; $ . getJSON ( langstr_query , function ( langstrings ) { langstrings . results . bindings . forEach ( function ( item ) { abbr_langnames [ item . abbr . value ] = item . langLabel . value ; langnames_abbr [ item . langLabel . value ] = item . abbr . value ; langnames . push ( item . langLabel . value ) ; } ) ; langnames . sort ( ) ; resetLang ( ) ; setFallbackLangs ( ) ; $ ( "#map-menu-container .top" ) . append ( "<div id=languageSelector onClick=\"$('#languageSelector ul').toggleClass('open');\">" + "<span lang=en>Choose Language:</span>" + "<ul></ul>" + "</div>" ) ; langnames . forEach ( function ( item ) { var langcode = langnames_abbr [ item ] ; var is_default = ( langcode == current_lang ) ? " class=default" : "" ; console . log ( "adding lang '" + langcode + "' (" + item + ")" ) ; $ ( "#languageSelector ul" ) . append ( "<li targetlang=" + langcode + is_default + " onClick='switchToLang(\"" + langcode + "\");'>" + item + "</li>" ) ; } ) ; } ) ; }
get languages for UI from our Wikibase, and pick languages that are translated there
get languages for UI from our Wikibase and pick languages that are translated there
//Q5 is arbitrary. Choose one that gets translated for sure.