Add Card Translations

This commit is contained in:
Nathan Chu
2020-09-28 12:19:12 -04:00
parent 057ff69ac2
commit b529b25320
8 changed files with 174 additions and 14 deletions
+28 -2
View File
@@ -28,8 +28,34 @@ const renderRepoCard = (repo, options = {}) => {
bg_color,
show_owner,
theme = "default_repocard",
lang = "en",
} = options;
const translations = {
template: {
cn: "模板",
de: "Vorlage",
en: "Template",
es: "Modelo",
fr: "Modèle",
it: "Modella",
ja: "テンプレート",
kr: "주형",
"pt-br": "Modelo",
},
archived: {
cn: "已封存",
de: "Archiviert",
en: "Archived",
es: "Archivé",
fr: "Archivé",
it: "Archiviata",
ja: "アーカイブ済み",
kr: "보관 됨",
"pt-br": "Arquivada",
},
}
const header = show_owner ? nameWithOwner : name;
const langName = (primaryLanguage && primaryLanguage.name) || "Unspecified";
const langColor = (primaryLanguage && primaryLanguage.color) || "#333";
@@ -132,9 +158,9 @@ const renderRepoCard = (repo, options = {}) => {
return card.render(`
${
isTemplate
? getBadgeSVG("Template")
? getBadgeSVG(translations.template[lang] || "Template")
: isArchived
? getBadgeSVG("Archived")
? getBadgeSVG(translations.archived[lang] || "Archived")
: ""
}
+77 -7
View File
@@ -66,6 +66,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
bg_color,
theme = "default",
custom_title,
lang = "en",
} = options;
const lheight = parseInt(line_height, 10);
@@ -79,17 +80,87 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
theme,
});
const apostrophe = ["x", "s"].includes(name.slice(-1)) ? "" : "s";
const translations = {
title: {
cn: `${encodeHTML(name)}的GitHub统计`,
de: `${encodeHTML(name) + apostrophe} GitHub-Statistiken`,
en: `${encodeHTML(name)}'${apostrophe} GitHub Stats`,
es: `Estadísticas de GitHub de ${encodeHTML(name)}`,
fr: `Statistiques GitHub de ${encodeHTML(name)}`,
it: `Statistiche GitHub di ${encodeHTML(name)}`,
ja: `${encodeHTML(name)}のGitHub統計`,
kr: `${encodeHTML(name)}의 GitHub 통계`,
"pt-br": `Estatísticas do GitHub de ${encodeHTML(name)}`,
},
stars: {
cn: "总星数",
de: "Insgesamt Sterne",
en: "Total Stars",
es: "Estrellas totales",
fr: "Total d'étoiles",
it: "Stelle totali",
ja: "星の合計",
kr: "총 별",
"pt-br": "Total de estrelas",
},
commits: {
cn: "总承诺",
de: "Total Commits",
en: "Total Commits",
es: "Compromisos totales",
fr: "Total des engagements",
it: "Impegni totali",
ja: "総コミット",
kr: "총 커밋",
"pt-br": "Total de compromissos",
},
prs: {
cn: "总公关",
de: "PRs insgesamt",
en: "Total PRs",
es: "RP totales",
fr: "Total des PR",
it: "PR totali",
ja: "合計PR",
kr: "총 PR",
"pt-br": "Total de PRs",
},
issues: {
cn: "总发行量",
de: "Gesamtausgaben",
en: "Total Issues",
es: "Problemas totales",
fr: "Nombre total de problèmes",
it: "Problemi totali",
ja: "総問題",
kr: "총 문제",
"pt-br": "Total de problemas",
},
contribs: {
cn: "有助于",
de: "Beigetragen zu",
en: "Contributed to",
es: "Contribuido a",
fr: "Contribué à",
it: "Ha contribuito a",
ja: "に貢献しました",
kr: "에 기여하다",
"pt-br": "Contribuiu para",
}
}
// Meta data for creating text nodes with createTextNode function
const STATS = {
stars: {
icon: icons.star,
label: "Total Stars",
label: translations.stars[lang] || "Total Stars",
value: totalStars,
id: "stars",
},
commits: {
icon: icons.commits,
label: `Total Commits${
label: `${translations.commits[lang] || "Total Commits"}${
include_all_commits ? "" : ` (${new Date().getFullYear()})`
}`,
value: totalCommits,
@@ -97,19 +168,19 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
},
prs: {
icon: icons.prs,
label: "Total PRs",
label: translations.prs[lang] || "Total PRs",
value: totalPRs,
id: "prs",
},
issues: {
icon: icons.issues,
label: "Total Issues",
label: translations.issues[lang] || "Total Issues",
value: totalIssues,
id: "issues",
},
contribs: {
icon: icons.contribs,
label: "Contributed to",
label: translations.contribs[lang] || "Contributed to",
value: contributedTo,
id: "contribs",
},
@@ -166,10 +237,9 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
progress,
});
const apostrophe = ["x", "s"].includes(name.slice(-1)) ? "" : "s";
const card = new Card({
customTitle: custom_title,
defaultTitle: `${encodeHTML(name)}'${apostrophe} GitHub Stats`,
defaultTitle: translations.title[lang] || `${encodeHTML(name)}'${apostrophe} GitHub Stats`,
width: 495,
height,
colors: {
+16 -1
View File
@@ -70,11 +70,26 @@ const renderTopLanguages = (topLangs, options = {}) => {
theme,
layout,
custom_title,
lang= "en",
} = options;
let langs = Object.values(topLangs);
let langsToHide = {};
const translations = {
title: {
cn: "最常用的语言",
de: "Meist verwendete Sprachen",
en: "Most Used Languages",
es: "Idiomas más usados",
fr: "Langues les plus utilisées",
it: "Lingue più utilizzate",
ja: "最もよく使われる言語",
kr: "가장 많이 사용되는 언어",
"pt-br": "Línguas Mais Usadas",
},
}
// populate langsToHide map for quick lookup
// while filtering out
if (hide) {
@@ -172,7 +187,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
const card = new Card({
customTitle: custom_title,
defaultTitle: "Most Used Languages",
defaultTitle: translations.title[lang] || "Most Used Languages",
width,
height,
colors: {
+30 -4
View File
@@ -3,9 +3,9 @@ const { getStyles } = require("../getStyles");
const { getCardColors, FlexLayout } = require("../common/utils");
const { createProgressNode } = require("../common/createProgressNode");
const noCodingActivityNode = ({ color }) => {
const noCodingActivityNode = ({ color, text }) => {
return `
<text x="25" y="11" class="stat bold" fill="${color}">No coding activity this week</text>
<text x="25" y="11" class="stat bold" fill="${color}">${text}</text>
`;
};
@@ -60,8 +60,34 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
theme = "default",
hide_progress,
custom_title,
lang = "en",
} = options;
const translations = {
title: {
cn: "Wakatime周统计",
de: "Wakatime Week Stats",
en: "Wakatime Week Stats",
es: "Estadísticas de la semana de Wakatime",
fr: "Statistiques de la semaine Wakatime",
it: "Statistiche della settimana di Wakatime",
ja: "ワカタイムウィーク統計",
kr: "Wakatime 주간 통계",
"pt-br": "Estatísticas da semana Wakatime",
},
noCodingActivity: {
cn: "本周没有编码活动",
de: "Keine Codierungsaktivität diese Woche",
en: "No coding activity this week",
es: "No hay actividad de codificación esta semana",
fr: "Aucune activité de codage cette semaine",
it: "Nessuna attività di codifica questa settimana",
ja: "今週のコーディング活動はありません",
kr: "이번 주 코딩 활동 없음",
"pt-br": "Nenhuma atividade de codificação esta semana",
},
}
const lheight = parseInt(line_height, 10);
// returns theme based colors with proper overrides and defaults
@@ -101,7 +127,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
const card = new Card({
customTitle: custom_title,
defaultTitle: "Wakatime Week Stats",
defaultTitle: translations.title[lang] || "Wakatime Week Stats",
width: 495,
height,
colors: {
@@ -126,7 +152,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
${FlexLayout({
items: statItems.length
? statItems
: [noCodingActivityNode({ color: textColor })],
: [noCodingActivityNode({ color: textColor, text: translations.noCodingActivity[lang] || "No coding activity this week" })],
gap: lheight,
direction: "column",
}).join("")}