Files
inbraille/public/modules/i18n.js
T
Lucas RayanandClaude Sonnet 5.5 a9aec5abe4
Release / Plano (reaproveitar a imagem?) (push) Successful in 8s
CI / Trivy (dependências, segredos e configuração) (push) Failing after 8s
Release / ci (push) Failing after 9s
CI / Testes e imagem Docker (linux/arm64) (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Skipped
Release / Cria a release no Gitea (push) Skipped
Recover InBraille from the production image (1.3.1) and move it to Gitea
The GitHub account was suspended and the repository had no backup. The deployed code
(src/, public/, index.html, main.py, requirements.txt) was extracted from the production
image 1.3.1. The tests, Dockerfile, compose files, SECURITY.md, CHANGELOG.md and README were
rebuilt from the records of the work sessions that created them; LICENSE, .gitignore,
robots.txt and sitemap.xml were recreated. CI now runs on Gitea Actions.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 00:15:01 -03:00

68 lines
2.1 KiB
JavaScript

import translations from '../translations.js';
import { state } from './state.js';
export function getTranslation(key) {
const dict = translations[state.page_language] || translations["pt-BR"];
return dict[key];
}
export function setLanguage(lang, onLanguageChanged) {
state.page_language = lang;
document.documentElement.lang = lang;
const dict = translations[lang] || translations["pt-BR"];
if (dict.page_title) {
document.title = dict.page_title;
}
const metaDesc = document.querySelector('meta[name="description"]');
if (metaDesc && dict.meta_description) {
metaDesc.setAttribute("content", dict.meta_description);
}
document.querySelectorAll("[data-i18n]").forEach(elem => {
const key = elem.getAttribute("data-i18n");
if (dict[key] !== undefined) {
elem.textContent = dict[key];
}
});
document.querySelectorAll("[data-i18n-placeholder]").forEach(elem => {
const key = elem.getAttribute("data-i18n-placeholder");
if (dict[key] !== undefined) {
elem.setAttribute("placeholder", dict[key]);
}
});
updateLangMenu(lang);
if (onLanguageChanged) {
onLanguageChanged();
}
}
function updateLangMenu(lang) {
const labelElem = document.querySelector("#current-lang-label");
if (!labelElem) return;
if (lang === "pt-BR") {
labelElem.innerHTML = "🇧🇷 Português";
} else if (lang === "en") {
labelElem.innerHTML = "🇺🇸 English";
} else if (lang === "zh") {
labelElem.innerHTML = "🇨🇳 中文";
}
const buttons = document.querySelectorAll("#lang_dropdown button[data-lang]");
buttons.forEach(btn => {
if (btn.getAttribute("data-lang") === lang) {
btn.className = "w-full text-left flex items-center gap-3 px-4 py-2 bg-blue-50 text-blue-600 font-semibold";
} else {
btn.className = "w-full text-left flex items-center gap-3 px-4 py-2 text-gray-700 hover:bg-gray-50";
}
});
const details = document.querySelector("#lang_dropdown");
if (details) {
details.removeAttribute("open");
}
}