-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlocale.js
More file actions
74 lines (64 loc) · 2.37 KB
/
locale.js
File metadata and controls
74 lines (64 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const traducoes = {
"pt-BR": {
titulo: "Jogo do número secreto",
escolhaNumero: "Escolha um número entre 1 e {limite}",
acertou: "Acertou!",
tentativas:
"Você descobriu o número secreto em {tentativas} {palavraTentativas}!",
numeroMaior: "O número secreto é maior!",
numeroMenor: "O número secreto é menor!",
btnChutar: "Chutar",
btnNovoJogo: "Novo jogo",
dificuldadeFacil: "🟢 Fácil (1-10)",
dificuldadeMedio: "🟡 Médio (1-50)",
dificuldadeDificil: "🔴 Difícil (1-100)",
},
"en-US": {
titulo: "Secret Number Game",
escolhaNumero: "Pick a number between 1 and {limite}",
acertou: "You got it!",
tentativas:
"You found the secret number in {tentativas} {palavraTentativas}!",
numeroMaior: "The secret number is higher!",
numeroMenor: "The secret number is lower!",
btnChutar: "Guess",
btnNovoJogo: "New game",
dificuldadeFacil: "🟢 Easy (1-10)",
dificuldadeMedio: "🟡 Medium (1-50)",
dificuldadeDificil: "🔴 Hard (1-100)",
},
};
var idiomaAtual = localStorage.getItem("idioma") || "pt-BR";
document.addEventListener("DOMContentLoaded", () => {
const selectIdioma = document.getElementById("select-idioma");
if (selectIdioma) selectIdioma.value = idiomaAtual;
// Definir a dificuldade salva no localStorage
const dificuldadeSalva = localStorage.getItem("dificuldade") || "10";
const selectDificuldade = document.getElementById("select-dificuldade");
if (selectDificuldade) selectDificuldade.value = dificuldadeSalva;
atualizarTextosDificuldade();
});
function t(chave, params = {}) {
let texto = traducoes[idiomaAtual][chave] || chave;
for (const key in params) {
texto = texto.replace(`{${key}}`, params[key]);
}
return texto;
}
function mudarIdioma(novoIdioma) {
idiomaAtual = novoIdioma;
localStorage.setItem("idioma", novoIdioma);
atualizarTextosDificuldade();
if (typeof exibirMensagemInicial === "function") {
exibirMensagemInicial();
}
}
function atualizarTextosDificuldade() {
const selectDificuldade = document.getElementById("select-dificuldade");
if (selectDificuldade) {
const options = selectDificuldade.options;
if (options[0]) options[0].textContent = t("dificuldadeFacil");
if (options[1]) options[1].textContent = t("dificuldadeMedio");
if (options[2]) options[2].textContent = t("dificuldadeDificil");
}
}