feat: card locale translations (#509)

* Add Card Translations

* Add tests and documentation for `?lang` option

* Card Translations: update Italian

* Run Prettier

* Correct German Translations.

Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>

* refactor: added i18n class to manage translation logic & improved code

* Make the new src/translations.js more concise

* Update translations.js

Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>

* Revert 4175484d69289e4ee7283ab968b8e71c3c5d77df

* fix: overlap because of language length

Co-authored-by: lrusso96 <russo.1699981@studenti.uniroma1.it>
Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com>
Co-authored-by: Anurag <hazru.anurag@gmail.com>
This commit is contained in:
Nathan Chu
2020-10-04 13:35:15 +05:30
committed by GitHub
co-authored by lrusso96 schmelto Anurag
parent 2707d07453
commit f1df178643
16 changed files with 337 additions and 27 deletions
+25
View File
@@ -307,4 +307,29 @@ describe("Test renderRepoCard", () => {
});
expect(queryByTestId(document.body, "badge")).toBeNull();
});
it("should render translated badges", () => {
document.body.innerHTML = renderRepoCard(
{
...data_repo.repository,
isArchived: true,
},
{
locale: "cn",
},
);
expect(queryByTestId(document.body, "badge")).toHaveTextContent("已封存");
document.body.innerHTML = renderRepoCard(
{
...data_repo.repository,
isTemplate: true,
},
{
locale: "cn",
},
);
expect(queryByTestId(document.body, "badge")).toHaveTextContent("模板");
});
});
+32
View File
@@ -209,4 +209,36 @@ describe("Test renderStatsCard", () => {
queryByTestId(document.body, "stars").previousElementSibling, // the label
).not.toHaveAttribute("x");
});
it("should render translations", () => {
document.body.innerHTML = renderStatsCard(stats, { locale: "cn" });
expect(document.getElementsByClassName("header")[0].textContent).toBe(
"Anurag Hazra的GitHub统计",
);
expect(
document.querySelector(
'g[transform="translate(0, 0)"]>.stagger>.stat.bold',
).textContent,
).toBe("总星数:");
expect(
document.querySelector(
'g[transform="translate(0, 25)"]>.stagger>.stat.bold',
).textContent,
).toBe("总承诺 (2020):");
expect(
document.querySelector(
'g[transform="translate(0, 50)"]>.stagger>.stat.bold',
).textContent,
).toBe("总公关:");
expect(
document.querySelector(
'g[transform="translate(0, 75)"]>.stagger>.stat.bold',
).textContent,
).toBe("总发行量:");
expect(
document.querySelector(
'g[transform="translate(0, 100)"]>.stagger>.stat.bold',
).textContent,
).toBe("有助于:");
});
});
+7
View File
@@ -216,4 +216,11 @@ describe("Test renderTopLanguages", () => {
"60.00",
);
});
it("should render a translated title", () => {
document.body.innerHTML = renderTopLanguages(langs, { locale: "cn" });
expect(document.getElementsByClassName("header")[0].textContent).toBe(
"最常用的语言",
);
});
});
+11
View File
@@ -113,4 +113,15 @@ describe("Test Render Wakatime Card", () => {
"
`);
});
it("should render translations", () => {
document.body.innerHTML = renderWakatimeCard({}, { locale: "cn" });
expect(document.getElementsByClassName("header")[0].textContent).toBe(
"Wakatime周统计",
);
expect(
document.querySelector('g[transform="translate(0, 0)"]>text.stat.bold')
.textContent,
).toBe("本周没有编码活动");
});
});