Skip to content

Commit b88df81

Browse files
adiciona versão experimental de tradutor
1 parent f5a4e0b commit b88df81

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

docs/js/translate.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function insertTranslationWidget() {
2+
const header = document.querySelector(".md-header__inner");
3+
if (!header || document.getElementById("lang-select")) return;
4+
5+
const select = document.createElement("select");
6+
select.id = "lang-select";
7+
select.style.marginLeft = "auto";
8+
select.innerHTML = `
9+
<option value="pt">PT</option>
10+
<option value="en">EN</option>
11+
<option value="es">ES</option>
12+
`;
13+
14+
select.addEventListener("change", () => {
15+
translatePage(select.value);
16+
});
17+
18+
header.appendChild(select);
19+
}
20+
21+
async function translateText(text, target) {
22+
try {
23+
const url =
24+
"https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" +
25+
target +
26+
"&dt=t&q=" +
27+
encodeURIComponent(text);
28+
const response = await fetch(url);
29+
if (!response.ok) return text;
30+
const data = await response.json();
31+
return data[0]?.map((part) => part[0]).join("") || text;
32+
} catch (e) {
33+
console.error("Translation error", e);
34+
return text;
35+
}
36+
}
37+
38+
async function translatePage(target) {
39+
const elements = document.querySelectorAll(
40+
"main .md-content p, main .md-content li"
41+
);
42+
for (const el of elements) {
43+
const originalText = el.innerText.trim();
44+
if (!originalText) continue;
45+
const translated = await translateText(originalText, target);
46+
el.innerText = translated;
47+
}
48+
}
49+
50+
document$.subscribe(() => {
51+
insertTranslationWidget();
52+
});

docs/tpi_tpe/tpi1_tpe1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ d) Elas produzem software menos complexo, o que facilita a manutenção.
1515

1616
> Equipes que produzem muitos bugs tendem a desperdiçar tempo em um ciclo eterno no qual desenvolvedores criam bugs, clientes (ou QAs dedicados) encontram os bugs, desenvolvedores corrigem os bugs, clientes encontram um novo conjunto de bugs, e assim por diante.
1717
18-
Teams that produce many bugs tend to waste time in an eternal loop where developers write bugs, customers (or dedicated QAs) find the bugs, developers fix the bugs, customers find a different set of bugs, and so on.
18+
Teams that produce many bugs tend to waste time in an eternal loop where developers write bugs, customers (or dedicated QAs) find the bugs, developers fix the bugs, customers find a different set of bugs, and so on.
1919

2020
— Aniche, _Effective Software Testing_, Capítulo 1, página 15 do PDF
2121

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extra_javascript:
1111
- js/shooting-stars.js
1212
- js/starfield.js
1313
- js/night-sky.js
14+
- js/translate.js
1415

1516
plugins:
1617
- search

0 commit comments

Comments
 (0)