// In a browser where the language is set to French
localize();

var currentLang;
// You can also override the language detection, and pass in a language code
//$("[data-localize]").localize("main", { language: "fr" });
function changeLangFR() {
  localize("fr");
}

// This code defines a function that sets the language to English.
function changeLangEN() {
  localize("en");
}

function refreshBooks() {
  $("[data-localize]").localize("books", {
    pathPrefix: "lang",
    language: currentLang,
  });
}

function refreshLoc() {
  localize(currentLang);
}

// Function to fill a data-localize attribute and update DOM
function setLocalizeDataAttr(className, dataValue) {
  $("#" + className)
    .data("localize", dataValue)
    .attr("data-localize", dataValue);
}

function localize(lang) {
  var overrideLang = "language:" + (lang ? lang : "");
  $("[data-localize]")
    .localize("main", {
      pathPrefix: "lang",
      overrideLang,
    })
    .localize("books", {
      pathPrefix: "lang",
      overrideLang,
    });
  currentLang = lang;
}