carregandoLinguagem.js 937 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Carregando idiomas - fetch API
  2. let idiomaEscolhido = 1;
  3. let idiomas = {};
  4. let idiomasURL = [
  5. "lang/en_US",
  6. "lang/pt_BR"
  7. ];
  8. function escolherIdioma(idioma) {
  9. if (idioma == "en_US") idiomaEscolhido = 0;
  10. else if (idioma == "pt_BR") idiomaEscolhido = 1;
  11. }
  12. function loadLangs() {
  13. var init = {
  14. mode: "same-origin"
  15. };
  16. fetch(idiomasURL[idiomaEscolhido], init)
  17. .then(response => response.text())
  18. .then(function (text) {
  19. let msg = text.split("\n"); // quebra mensagem por linha
  20. msg.forEach((key) => {
  21. try {
  22. let line = key.split("="); // divide antes e depois do =
  23. let a = line[0], b = line[1];
  24. a = a.trim();
  25. b = b.trim();
  26. idiomas[a] = b;
  27. }catch{
  28. //console.log("erro de sintaxe");
  29. }
  30. });
  31. });
  32. }
  33. function printLangs() {
  34. document.getElementById("texto").value = idiomas.loading + '\n' + idiomas["menu_back"];
  35. console.log(idiomas);
  36. }