Skip to content

Commit

Permalink
add: back locale to stats card
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Nov 23, 2024
1 parent b0aed75 commit c8e5706
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 141 deletions.
5 changes: 5 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fetchStats } from "../src/fetchers/stats-fetcher.js";
export default async (req, res) => {
const {
username,
hide,
title,
description,
show_icons,
Expand All @@ -22,6 +23,8 @@ export default async (req, res) => {
email,
exclude_repo,
custom_title,
locale,
disable_animations,
border_radius,
number_format,
hide_border,
Expand Down Expand Up @@ -77,6 +80,8 @@ export default async (req, res) => {
custom_title,
border_radius,
number_format,
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
dark_bg,
}),
);
Expand Down
3 changes: 1 addition & 2 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import langCard from "./api/top-langs.js";
import wakatimeCard from "./api/wakatime.js";
import gistCard from "./api/gist.js";
import express from "express";
import { inject } from "@vercel/analytics";

const app = express();
app.listen(process.env.port || 9000);
Expand All @@ -18,4 +17,4 @@ app.get("/top-langs", langCard);
app.get("/wakatime", wakatimeCard);
app.get("/gist", gistCard);

inject();

68 changes: 12 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"prettier": "^3.3.3"
},
"dependencies": {
"@vercel/analytics": "^1.4.0",
"axios": "^1.7.7",
"dotenv": "^16.4.5",
"emoji-name-map": "^1.2.8",
Expand Down
41 changes: 22 additions & 19 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
measureText,
} from "../common/utils.js";

import { statCardLocales } from "../translations.js";
import { I18n } from "../common/I18n.js";

const CARD_LEFT_MIN_WIDTH = 250;
const CARD_DEFAULT_WIDTH = 250;
const RANK_CARD_LEFT_MIN_WIDTH = 756;
Expand Down Expand Up @@ -169,8 +172,8 @@ const renderStatsCard = (stats, options = {}) => {
border_radius,
border_color,
number_format = "short",
locale,
disable_animations = false,
rank_icon = "default",
title_text,
description_text,
email,
Expand All @@ -189,43 +192,54 @@ const renderStatsCard = (stats, options = {}) => {
theme,
});

// Meta data for creating text nodes

const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase())
? ""
: "s";
const i18n = new I18n({
locale,
translations: statCardLocales({ name, apostrophe }),
});


const STATS = {
stars: {
icon: icons.star,
label: "Total Stars",
label: i18n.t("statcard.totalstars"),
value: totalStars,
id: "stars",
},
commits: {
icon: icons.commits,
label: `Commits${include_all_commits ? "" : ` (${new Date().getFullYear()})`}`,
label: `${i18n.t("statcard.commits")}${
include_all_commits ? "" : ` (${new Date().getFullYear()})`
}`,
value: totalCommits,
id: "commits",
},
prs: {
icon: icons.prs,
label: "Pull Requests",
label: i18n.t("statcard.prs"),
value: totalPRs,
id: "prs",
},
issues: {
icon: icons.issues,
label: "Issues",
label: i18n.t("statcard.issues"),
value: totalIssues,
id: "issues",
},
contribs: {
icon: icons.contribs,
label: "Contributed to",
label: i18n.t("statcard.contribs"),
value: contributedTo,
id: "contribs",
},
};

STATS.prs_merged = {
icon: icons.prs_merged,
label: "PRs Merged",
label: i18n.t("statcard.prs-merged"),
value: totalPRsMerged,
id: "prs_merged",
};
Expand Down Expand Up @@ -365,17 +379,6 @@ const renderStatsCard = (stats, options = {}) => {
card.disableAnimations();
}

const rankCircle = hide_rank
? ""
: `<g data-testid="rank-circle"
transform="translate(${cardWidth / 2}, ${height / 2 - 50})">
<circle class="rank-circle-rim" cx="-10" cy="8" r="40" />
<circle class="rank-circle" cx="-10" cy="8" r="40" />
<g class="rank-text">
${rankIcon(rank_icon, rank?.level, rank?.percentile)}
</g>
</g>`;

const labelsLeft = Object.keys(STATS)
.filter(
(key) => !hide.includes(key) && key !== "issues" && key !== "contribs",
Expand Down
8 changes: 4 additions & 4 deletions src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type CommonOptions = {
title_color: string;
icon_color: string;
text_color: string;
bg_color: string;
theme: ThemeNames;
dark_bg: number;
border_radius: number;
Expand All @@ -15,9 +14,9 @@ export type CommonOptions = {
};

export type StatCardOptions = CommonOptions & {
hide: string[];
show_icons: boolean;
hide_title: boolean;
card_width: number;
hide_rank: boolean;
include_all_commits: boolean;
line_height: number | string;
Expand All @@ -26,10 +25,11 @@ export type StatCardOptions = CommonOptions & {
number_format: string;
ring_color: string;
text_bold: boolean;
rank_icon: RankIcon;
title_text: string;
email: string;
email: string; // Deprecated
footer: string;
description_text: string;
layout: "wide" | "normal";
};

export type RepoCardOptions = CommonOptions & {
Expand Down
Loading

0 comments on commit c8e5706

Please sign in to comment.