@stats-forge/github-stats-forge-core 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/build/api/contributed-to.js +1 -1
  2. package/build/api/gist.js +1 -1
  3. package/build/api/index.d.ts +1 -0
  4. package/build/api/index.d.ts.map +1 -1
  5. package/build/api/index.js +1 -0
  6. package/build/api/organization.d.ts +29 -0
  7. package/build/api/organization.d.ts.map +1 -0
  8. package/build/api/organization.js +53 -0
  9. package/build/api/params.js +1 -1
  10. package/build/api/pin.js +1 -1
  11. package/build/api/stats.js +1 -1
  12. package/build/api/top-langs.js +1 -1
  13. package/build/api/wakatime.js +1 -1
  14. package/build/cards/{contributed-to.d.ts → contributed-to/index.d.ts} +3 -3
  15. package/build/cards/contributed-to/index.d.ts.map +1 -0
  16. package/build/cards/{contributed-to.js → contributed-to/index.js} +31 -30
  17. package/build/cards/contributed-to/locales.d.ts +38 -0
  18. package/build/cards/contributed-to/locales.d.ts.map +1 -0
  19. package/build/cards/contributed-to/locales.js +39 -0
  20. package/build/cards/{gist.d.ts → gist/index.d.ts} +3 -3
  21. package/build/cards/gist/index.d.ts.map +1 -0
  22. package/build/cards/{gist.js → gist/index.js} +20 -15
  23. package/build/cards/gist/locales.d.ts +14 -0
  24. package/build/cards/gist/locales.d.ts.map +1 -0
  25. package/build/cards/gist/locales.js +15 -0
  26. package/build/cards/organization/index.d.ts +36 -0
  27. package/build/cards/organization/index.d.ts.map +1 -0
  28. package/build/cards/organization/index.js +226 -0
  29. package/build/cards/organization/locales.d.ts +47 -0
  30. package/build/cards/organization/locales.d.ts.map +1 -0
  31. package/build/cards/organization/locales.js +47 -0
  32. package/build/cards/{repo.d.ts → repo/index.d.ts} +3 -3
  33. package/build/cards/repo/index.d.ts.map +1 -0
  34. package/build/cards/{repo.js → repo/index.js} +20 -23
  35. package/build/cards/repo/locales.d.ts +129 -0
  36. package/build/cards/repo/locales.d.ts.map +1 -0
  37. package/build/cards/repo/locales.js +129 -0
  38. package/build/cards/{stats.d.ts → stats/index.d.ts} +3 -3
  39. package/build/cards/stats/index.d.ts.map +1 -0
  40. package/build/cards/{stats.js → stats/index.js} +38 -42
  41. package/build/cards/stats/locales.d.ts +621 -0
  42. package/build/cards/stats/locales.d.ts.map +1 -0
  43. package/build/cards/stats/locales.js +623 -0
  44. package/build/cards/{top-languages.d.ts → top-languages/index.d.ts} +3 -3
  45. package/build/cards/top-languages/index.d.ts.map +1 -0
  46. package/build/cards/{top-languages.js → top-languages/index.js} +13 -16
  47. package/build/cards/top-languages/locales.d.ts +103 -0
  48. package/build/cards/top-languages/locales.d.ts.map +1 -0
  49. package/build/cards/top-languages/locales.js +103 -0
  50. package/build/cards/{wakatime.d.ts → wakatime/index.d.ts} +3 -3
  51. package/build/cards/wakatime/index.d.ts.map +1 -0
  52. package/build/cards/{wakatime.js → wakatime/index.js} +22 -23
  53. package/build/cards/wakatime/locales.d.ts +250 -0
  54. package/build/cards/wakatime/locales.d.ts.map +1 -0
  55. package/build/cards/wakatime/locales.js +250 -0
  56. package/build/common/brand.d.ts +1 -0
  57. package/build/common/brand.d.ts.map +1 -1
  58. package/build/common/brand.js +1 -0
  59. package/build/common/error.d.ts +3 -1
  60. package/build/common/error.d.ts.map +1 -1
  61. package/build/common/error.js +3 -1
  62. package/build/common/http.d.ts +2 -0
  63. package/build/common/http.d.ts.map +1 -1
  64. package/build/common/icons.d.ts +5 -0
  65. package/build/common/icons.d.ts.map +1 -1
  66. package/build/common/icons.js +19 -4
  67. package/build/common/languageColors.json +2 -0
  68. package/build/common/locales.d.ts +59 -0
  69. package/build/common/locales.d.ts.map +1 -0
  70. package/build/common/locales.js +59 -0
  71. package/build/common/localize.d.ts +60 -0
  72. package/build/common/localize.d.ts.map +1 -0
  73. package/build/common/localize.js +163 -0
  74. package/build/fetchers/index.d.ts +2 -1
  75. package/build/fetchers/index.d.ts.map +1 -1
  76. package/build/fetchers/index.js +1 -0
  77. package/build/fetchers/organization.d.ts +15 -0
  78. package/build/fetchers/organization.d.ts.map +1 -0
  79. package/build/fetchers/organization.js +130 -0
  80. package/build/fetchers/types.d.ts +39 -0
  81. package/build/fetchers/types.d.ts.map +1 -1
  82. package/build/graphql/generated/organization.d.ts +88 -0
  83. package/build/graphql/generated/organization.d.ts.map +1 -0
  84. package/build/graphql/generated/organization.js +59 -0
  85. package/package.json +1 -1
  86. package/src/api/contributed-to.ts +1 -1
  87. package/src/api/gist.ts +1 -1
  88. package/src/api/index.ts +1 -0
  89. package/src/api/organization.ts +90 -0
  90. package/src/api/params.ts +1 -1
  91. package/src/api/pin.ts +1 -1
  92. package/src/api/stats.ts +1 -1
  93. package/src/api/top-langs.ts +1 -1
  94. package/src/api/wakatime.ts +1 -1
  95. package/src/cards/{contributed-to.ts → contributed-to/index.ts} +42 -39
  96. package/src/cards/contributed-to/locales.ts +41 -0
  97. package/src/cards/{gist.ts → gist/index.ts} +23 -20
  98. package/src/cards/gist/locales.ts +17 -0
  99. package/src/cards/organization/index.ts +359 -0
  100. package/src/cards/organization/locales.ts +49 -0
  101. package/src/cards/{repo.ts → repo/index.ts} +23 -26
  102. package/src/cards/repo/locales.ts +131 -0
  103. package/src/cards/{stats.ts → stats/index.ts} +48 -56
  104. package/src/cards/stats/locales.ts +625 -0
  105. package/src/cards/{top-languages.ts → top-languages/index.ts} +17 -20
  106. package/src/cards/top-languages/locales.ts +105 -0
  107. package/src/cards/{wakatime.ts → wakatime/index.ts} +26 -27
  108. package/src/cards/wakatime/locales.ts +252 -0
  109. package/src/common/brand.ts +1 -0
  110. package/src/common/error.ts +4 -0
  111. package/src/common/http.ts +6 -1
  112. package/src/common/icons.ts +20 -4
  113. package/src/common/languageColors.json +2 -0
  114. package/src/common/locales.ts +61 -0
  115. package/src/common/localize.ts +251 -0
  116. package/src/fetchers/index.ts +2 -0
  117. package/src/fetchers/organization.ts +172 -0
  118. package/src/fetchers/types.ts +37 -0
  119. package/src/graphql/generated/organization.ts +109 -0
  120. package/src/graphql/queries/organization.graphql +57 -0
  121. package/build/cards/contributed-to.d.ts.map +0 -1
  122. package/build/cards/gist.d.ts.map +0 -1
  123. package/build/cards/repo.d.ts.map +0 -1
  124. package/build/cards/stats.d.ts.map +0 -1
  125. package/build/cards/top-languages.d.ts.map +0 -1
  126. package/build/cards/wakatime.d.ts.map +0 -1
  127. package/build/common/I18n.d.ts +0 -21
  128. package/build/common/I18n.d.ts.map +0 -1
  129. package/build/common/I18n.js +0 -34
  130. package/build/translations.d.ts +0 -1212
  131. package/build/translations.d.ts.map +0 -1
  132. package/build/translations.js +0 -1213
  133. package/src/common/I18n.ts +0 -50
  134. package/src/translations.ts +0 -1239
@@ -0,0 +1,359 @@
1
+ import { CARD_ICON, CARD_WIDTH, FONT_SIZE, FONT_WEIGHT, font } from '../../common/brand.ts';
2
+ import { Card } from '../../common/Card.ts';
3
+ import { getLightDarkColors } from '../../common/color.ts';
4
+ import type { CardColors } from '../../common/color.ts';
5
+ import { CardError } from '../../common/error.ts';
6
+ import { kFormatter } from '../../common/fmt.ts';
7
+ import { icons } from '../../common/icons.ts';
8
+ import { localize } from '../../common/localize.ts';
9
+ import { parseEmojis } from '../../common/ops.ts';
10
+ import {
11
+ NUMBER_FORMATS,
12
+ createTextNode,
13
+ flexLayout,
14
+ measureText,
15
+ wrapTextMultiline,
16
+ } from '../../common/render.ts';
17
+ import type { OrganizationData } from '../../fetchers/types.ts';
18
+ import type { Child, CssChild } from '../../markup/index.ts';
19
+ import { el, rule } from '../../markup/index.ts';
20
+ import type { CardOptions, CommonCardOptions } from '../options.ts';
21
+
22
+ import { orgCardLocales } from './locales.ts';
23
+
24
+ const CARD_DEFAULT_WIDTH = CARD_WIDTH.standard;
25
+ /** Padding the card keeps at its edges; matches `Card`'s own `paddingX`. */
26
+ const CARD_PADDING_X = 25;
27
+ /** How far a stat row is translated into the card; see `createTextNode`. */
28
+ const STAT_ROW_X = 25;
29
+ /** `createTextNode`'s own label offset, which it applies only when icons are shown. */
30
+ const LABEL_X_OFFSET = 25;
31
+ /** Smallest gap kept between the longest label and its value. */
32
+ const LABEL_VALUE_GAP = 16;
33
+ const DESCRIPTION_FONT_SIZE = FONT_SIZE.meta;
34
+ const DESCRIPTION_LINE_HEIGHT_PX = 16;
35
+ const DESCRIPTION_MAX_LINES = 2;
36
+ /** Air between the description and the first stat row. */
37
+ const DESCRIPTION_GAP = 8;
38
+
39
+ /** Stats the card draws only when `show` names them. */
40
+ const SHOW_STATS = ['releases', 'commits', 'members', 'top_language', 'created'] as const;
41
+ type ShowStat = (typeof SHOW_STATS)[number];
42
+
43
+ /** Stats the card always draws, and so the ones `hide` has anything to remove. */
44
+ const HIDE_STATS = ['repos', 'stars', 'forks', 'watchers', 'open_issues', 'open_prs'] as const;
45
+ type HideStat = (typeof HIDE_STATS)[number];
46
+
47
+ type StatId = HideStat | ShowStat;
48
+
49
+ interface OrgCardOptions extends CommonCardOptions {
50
+ locale: string;
51
+ hide: Array<string>;
52
+ show: Array<string>;
53
+ show_icons: boolean;
54
+ hide_title: boolean;
55
+ hide_description: boolean;
56
+ card_width: number;
57
+ line_height: number | string;
58
+ custom_title: string;
59
+ disable_animations: boolean;
60
+ number_format: string;
61
+ text_bold: boolean;
62
+ }
63
+
64
+ /** Meta data for a stat, used to build its text node and accessibility label. */
65
+ interface StatItem {
66
+ icon: Child;
67
+ label: string;
68
+ value: number | string;
69
+ id: string;
70
+ }
71
+
72
+ /**
73
+ * @returns Card CSS styles.
74
+ */
75
+ const getStyles = ({
76
+ textColor,
77
+ iconColor,
78
+ show_icons,
79
+ }: {
80
+ textColor: string;
81
+ iconColor: string;
82
+ show_icons: boolean;
83
+ }): Array<CssChild> => [
84
+ rule('.stat', {
85
+ font: font('regular', 'body'),
86
+ fill: textColor,
87
+ 'font-variant-numeric': 'tabular-nums',
88
+ }),
89
+ rule('.description', { font: font('regular', 'meta'), fill: textColor, opacity: 0.9 }),
90
+ rule('.stagger', { opacity: 0, animation: 'fadeInAnimation 0.3s ease-in-out forwards' }),
91
+ rule('.not_bold', { 'font-weight': FONT_WEIGHT.regular, opacity: 0.75 }),
92
+ rule('.bold', { 'font-weight': FONT_WEIGHT.semibold }),
93
+ rule('.icon', { fill: iconColor, opacity: 0.75, display: show_icons ? 'block' : 'none' }),
94
+ ];
95
+
96
+ /**
97
+ * Renders the organization card.
98
+ *
99
+ * @returns The organization card SVG object.
100
+ */
101
+ const renderCard = (
102
+ organization: OrganizationData,
103
+ options: CardOptions<OrgCardOptions> = {},
104
+ ): string => {
105
+ const {
106
+ name,
107
+ description,
108
+ createdAt,
109
+ publicRepos,
110
+ totalStars,
111
+ totalForks,
112
+ totalWatchers,
113
+ openIssues,
114
+ openPRs,
115
+ totalReleases,
116
+ totalCommits,
117
+ publicMembers,
118
+ topLanguage,
119
+ truncated,
120
+ } = organization;
121
+ const {
122
+ hide = [],
123
+ show = [],
124
+ show_icons = true,
125
+ hide_title = false,
126
+ hide_border = false,
127
+ hide_description = false,
128
+ card_width,
129
+ line_height = 25,
130
+ text_bold = true,
131
+ custom_title,
132
+ border_radius,
133
+ number_format = 'short',
134
+ locale,
135
+ disable_animations = false,
136
+ } = options;
137
+
138
+ const lheight = Number.parseInt(String(line_height), 10);
139
+
140
+ const { lightColors, darkColors } = getLightDarkColors(options);
141
+
142
+ // Typed against the exported list, so a stat drawn here cannot be missing from it.
143
+ const shows = (stat: ShowStat): boolean => show.includes(stat);
144
+
145
+ const apostrophe = /s$/i.test(name.trim()) ? '' : 's';
146
+ const t = localize(orgCardLocales, locale);
147
+
148
+ /**
149
+ * A total the walk may have stopped short of reads as a lower bound.
150
+ *
151
+ * @returns The value, as the row draws it.
152
+ */
153
+ const total = (value: number): number | string =>
154
+ truncated
155
+ ? `${number_format.toLowerCase() === 'long' ? String(value) : kFormatter(value)}+`
156
+ : value;
157
+
158
+ const STATS: Partial<Record<StatId, StatItem>> = {
159
+ repos: {
160
+ icon: icons.repo,
161
+ label: t.repos(),
162
+ value: publicRepos,
163
+ id: 'repos',
164
+ },
165
+ stars: {
166
+ icon: icons.star,
167
+ label: t.stars(),
168
+ value: total(totalStars),
169
+ id: 'stars',
170
+ },
171
+ forks: {
172
+ icon: icons.fork,
173
+ label: t.forks(),
174
+ value: total(totalForks),
175
+ id: 'forks',
176
+ },
177
+ watchers: {
178
+ icon: icons.watchers,
179
+ label: t.watchers(),
180
+ value: total(totalWatchers),
181
+ id: 'watchers',
182
+ },
183
+ open_issues: {
184
+ icon: icons.issues,
185
+ label: t.openIssues(),
186
+ value: total(openIssues),
187
+ id: 'open_issues',
188
+ },
189
+ open_prs: {
190
+ icon: icons.prs,
191
+ label: t.openPrs(),
192
+ value: total(openPRs),
193
+ id: 'open_prs',
194
+ },
195
+ };
196
+
197
+ if (shows('releases')) {
198
+ STATS['releases'] = {
199
+ icon: icons.tag,
200
+ label: t.releases(),
201
+ value: total(totalReleases),
202
+ id: 'releases',
203
+ };
204
+ }
205
+ if (shows('commits')) {
206
+ STATS['commits'] = {
207
+ icon: icons.commits,
208
+ label: t.commits(),
209
+ value: total(totalCommits),
210
+ id: 'commits',
211
+ };
212
+ }
213
+
214
+ // A refused member count is `null`, and no row is better than a row reading "0".
215
+ if (shows('members') && publicMembers !== null) {
216
+ STATS['members'] = {
217
+ icon: icons.people,
218
+ label: t.members(),
219
+ value: publicMembers,
220
+ id: 'members',
221
+ };
222
+ }
223
+ if (shows('top_language')) {
224
+ STATS['top_language'] = {
225
+ icon: icons.code,
226
+ label: t.topLanguage(),
227
+ value: topLanguage?.name ?? t.unspecifiedLanguage(),
228
+ id: 'top_language',
229
+ };
230
+ }
231
+ if (shows('created')) {
232
+ const year = new Date(createdAt).getUTCFullYear();
233
+ STATS['created'] = {
234
+ icon: icons.calendar,
235
+ label: t.created(),
236
+ value: Number.isNaN(year) ? '—' : String(year),
237
+ id: 'created',
238
+ };
239
+ }
240
+
241
+ const visibleStats = Object.entries(STATS).filter(([key]) => !hide.includes(key));
242
+
243
+ if (visibleStats.length === 0) {
244
+ throw new CardError('Could not render organization card.', {
245
+ code: 'invalid_param',
246
+ secondaryMessage: 'At least one stat is required.',
247
+ });
248
+ }
249
+
250
+ const width = card_width && !Number.isNaN(card_width) ? card_width : CARD_DEFAULT_WIDTH;
251
+
252
+ const desc = hide_description ? '' : parseEmojis(description || t.noDescription());
253
+ const descriptionLines = desc
254
+ ? wrapTextMultiline(
255
+ desc,
256
+ width - 2 * CARD_PADDING_X,
257
+ DESCRIPTION_FONT_SIZE,
258
+ DESCRIPTION_MAX_LINES,
259
+ )
260
+ : [];
261
+ const statsTop =
262
+ descriptionLines.length > 0
263
+ ? descriptionLines.length * DESCRIPTION_LINE_HEIGHT_PX + DESCRIPTION_GAP
264
+ : 0;
265
+
266
+ const height = 45 + (visibleStats.length + 1) * lheight + statsTop;
267
+
268
+ // A value ends at the card's inner edge — or right after the longest label,
269
+ // on a card too narrow for that.
270
+ const widestLabel = Math.max(
271
+ ...visibleStats.map(([, stat]) => measureText(`${stat.label}:`, FONT_SIZE.body)),
272
+ );
273
+ const valueAnchorX = Math.round(
274
+ Math.max(
275
+ width - CARD_PADDING_X - STAT_ROW_X,
276
+ (show_icons ? LABEL_X_OFFSET : 0) + widestLabel + LABEL_VALUE_GAP,
277
+ ),
278
+ );
279
+
280
+ const statItems = visibleStats.map(([, stat], index) =>
281
+ createTextNode({
282
+ icon: stat.icon,
283
+ label: stat.label,
284
+ value: stat.value,
285
+ id: stat.id,
286
+ index,
287
+ showIcons: show_icons,
288
+ shiftValuePos: 0,
289
+ valueAnchorX,
290
+ bold: text_bold,
291
+ labelBold: false,
292
+ numberFormat: number_format,
293
+ }),
294
+ );
295
+
296
+ const card = new Card({
297
+ customTitle: custom_title,
298
+ defaultTitle: t.title({ name, apostrophe }),
299
+ titlePrefixIcon: CARD_ICON.organization,
300
+ width,
301
+ height,
302
+ border_radius,
303
+ colors: { light: lightColors, dark: darkColors },
304
+ });
305
+
306
+ card.setHideBorder(hide_border);
307
+ card.setHideTitle(hide_title);
308
+ const cardStyles = ({ textColor, iconColor }: CardColors): Array<CssChild> =>
309
+ getStyles({ textColor, iconColor, show_icons });
310
+ card.setCSS({ light: cardStyles, dark: cardStyles });
311
+
312
+ if (disable_animations) {
313
+ card.disableAnimations();
314
+ }
315
+
316
+ // `role="img"` hides the inner text from assistive tech, so everything the card
317
+ // shows has to be repeated here.
318
+ card.setAccessibilityLabel({
319
+ title: card.title,
320
+ desc: [
321
+ desc && `${desc}.`,
322
+ visibleStats.map(([, stat]) => `${stat.label}: ${String(stat.value)}`).join(', '),
323
+ ]
324
+ .filter(Boolean)
325
+ .join(' '),
326
+ });
327
+
328
+ const descriptionSvg =
329
+ descriptionLines.length > 0 &&
330
+ el(
331
+ 'text',
332
+ { class: 'description', 'data-testid': 'description', x: CARD_PADDING_X, y: -5 },
333
+ descriptionLines.map((line) => el('tspan', { dy: '1.2em', x: CARD_PADDING_X }, line)),
334
+ );
335
+
336
+ return card.render([
337
+ descriptionSvg,
338
+ el(
339
+ 'g',
340
+ { transform: `translate(0, ${statsTop})` },
341
+ flexLayout({ items: statItems, gap: lheight, direction: 'column' }),
342
+ ),
343
+ ]);
344
+ };
345
+
346
+ /**
347
+ * The card, and the values each of its options accepts, keyed by the option's own name.
348
+ * They ride on the renderer so a list cannot be found without what draws it;
349
+ * the api handler forwards them onto its own export, which is what a UI reads.
350
+ */
351
+ const renderOrganizationCard = Object.assign(renderCard, {
352
+ OPTIONS: {
353
+ show: SHOW_STATS,
354
+ hide: HIDE_STATS,
355
+ number_format: NUMBER_FORMATS,
356
+ },
357
+ });
358
+
359
+ export { renderOrganizationCard };
@@ -0,0 +1,49 @@
1
+ import { defineLocales } from '../../common/localize.ts';
2
+
3
+ /** The organization card's labels in the locales they have been translated into. */
4
+ const orgCardLocales = defineLocales({
5
+ title: {
6
+ en: `{name}'{apostrophe} GitHub Organization`,
7
+ },
8
+ noDescription: {
9
+ en: 'No description provided',
10
+ },
11
+ repos: {
12
+ en: 'Public repositories',
13
+ },
14
+ stars: {
15
+ en: 'Total stars',
16
+ },
17
+ forks: {
18
+ en: 'Total forks',
19
+ },
20
+ watchers: {
21
+ en: 'Total watchers',
22
+ },
23
+ openIssues: {
24
+ en: 'Open issues',
25
+ },
26
+ openPrs: {
27
+ en: 'Open PRs',
28
+ },
29
+ releases: {
30
+ en: 'Releases',
31
+ },
32
+ commits: {
33
+ en: 'Commits',
34
+ },
35
+ members: {
36
+ en: 'Public members',
37
+ },
38
+ topLanguage: {
39
+ en: 'Top language',
40
+ },
41
+ created: {
42
+ en: 'Created',
43
+ },
44
+ unspecifiedLanguage: {
45
+ en: 'Unspecified',
46
+ },
47
+ });
48
+
49
+ export { orgCardLocales };
@@ -1,10 +1,10 @@
1
- import { CARD_ICON, CARD_WIDTH, FONT_SIZE, FONT_WEIGHT, font } from '../common/brand.ts';
2
- import { Card } from '../common/Card.ts';
3
- import { getLightDarkColors } from '../common/color.ts';
4
- import { kFormatter } from '../common/fmt.ts';
5
- import { I18n } from '../common/I18n.ts';
6
- import { icons } from '../common/icons.ts';
7
- import { buildSearchFilter, clampValue, parseEmojis } from '../common/ops.ts';
1
+ import { CARD_ICON, CARD_WIDTH, FONT_SIZE, FONT_WEIGHT, font } from '../../common/brand.ts';
2
+ import { Card } from '../../common/Card.ts';
3
+ import { getLightDarkColors } from '../../common/color.ts';
4
+ import { kFormatter } from '../../common/fmt.ts';
5
+ import { icons } from '../../common/icons.ts';
6
+ import { localize } from '../../common/localize.ts';
7
+ import { buildSearchFilter, clampValue, parseEmojis } from '../../common/ops.ts';
8
8
  import {
9
9
  NUMBER_FORMATS,
10
10
  countWrappedLines,
@@ -16,13 +16,13 @@ import {
16
16
  measureText,
17
17
  wrappedTextNode,
18
18
  wrappedTextStyles,
19
- } from '../common/render.ts';
20
- import type { RepositoryData } from '../fetchers/types.ts';
21
- import type { Child, MarkupElement } from '../markup/index.ts';
22
- import { el, rule } from '../markup/index.ts';
23
- import { repoCardLocales } from '../translations.ts';
19
+ } from '../../common/render.ts';
20
+ import type { RepositoryData } from '../../fetchers/types.ts';
21
+ import type { Child, MarkupElement } from '../../markup/index.ts';
22
+ import { el, rule } from '../../markup/index.ts';
23
+ import type { CardOptions, CommonCardOptions } from '../options.ts';
24
24
 
25
- import type { CardOptions, CommonCardOptions } from './options.ts';
25
+ import { repoCardLocales } from './locales.ts';
26
26
 
27
27
  const ICON_SIZE = 16;
28
28
  const CARD_DEFAULT_WIDTH = CARD_WIDTH.standard;
@@ -137,10 +137,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
137
137
  ? CARD_DEFAULT_WIDTH + 30
138
138
  : CARD_DEFAULT_WIDTH;
139
139
 
140
- const i18n = new I18n({
141
- locale,
142
- translations: repoCardLocales,
143
- });
140
+ const t = localize(repoCardLocales, locale);
144
141
 
145
142
  // Typed against the exported list, so a stat drawn here cannot be missing from it.
146
143
  const shows = (stat: RepoShowStat): boolean => show.includes(stat);
@@ -151,7 +148,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
151
148
  if (shows('prs_authored')) {
152
149
  STATS['prs_authored'] = {
153
150
  icon: icons.prs,
154
- label: i18n.t('repocard.prs-authored'),
151
+ label: t.prsAuthored(),
155
152
  value: totalPRsAuthored,
156
153
  id: 'prs_authored',
157
154
  link: `https://github.com/search?q=${repoFilter}author%3A${encodedUsername}&amp;type=pullrequests`,
@@ -160,7 +157,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
160
157
  if (shows('prs_commented')) {
161
158
  STATS['prs_commented'] = {
162
159
  icon: icons.comments,
163
- label: i18n.t('repocard.prs-commented'),
160
+ label: t.prsCommented(),
164
161
  value: totalPRsCommented,
165
162
  id: 'prs_commented',
166
163
  link: `https://github.com/search?q=${repoFilter}commenter%3A${encodedUsername}+-author%3A${encodedUsername}&amp;type=pullrequests`,
@@ -169,7 +166,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
169
166
  if (shows('prs_reviewed')) {
170
167
  STATS['prs_reviewed'] = {
171
168
  icon: icons.reviews,
172
- label: i18n.t('repocard.prs-reviewed'),
169
+ label: t.prsReviewed(),
173
170
  value: totalPRsReviewed,
174
171
  id: 'prs_reviewed',
175
172
  link: `https://github.com/search?q=${repoFilter}reviewed-by%3A${encodedUsername}+-author%3A${encodedUsername}&amp;type=pullrequests`,
@@ -178,7 +175,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
178
175
  if (shows('issues_authored')) {
179
176
  STATS['issues_authored'] = {
180
177
  icon: icons.issues,
181
- label: i18n.t('repocard.issues-authored'),
178
+ label: t.issuesAuthored(),
182
179
  value: totalIssuesAuthored,
183
180
  id: 'issues_authored',
184
181
  link: `https://github.com/search?q=${repoFilter}author%3A${encodedUsername}&amp;type=issues`,
@@ -187,7 +184,7 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
187
184
  if (shows('issues_commented')) {
188
185
  STATS['issues_commented'] = {
189
186
  icon: icons.discussions_started,
190
- label: i18n.t('repocard.issues-commented'),
187
+ label: t.issuesCommented(),
191
188
  value: totalIssuesCommented,
192
189
  id: 'issues_commented',
193
190
  link: `https://github.com/search?q=${repoFilter}commenter%3A${encodedUsername}+-author%3A${encodedUsername}&amp;type=issues`,
@@ -215,9 +212,9 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
215
212
  const extraLHeight = Number.parseInt(String(line_height), 10);
216
213
  const lineHeight = 10;
217
214
  const header = show_owner ? nameWithOwner : name;
218
- const langName = primaryLanguage?.name || i18n.t('repocard.unspecified-language');
215
+ const langName = primaryLanguage?.name || t.unspecifiedLanguage();
219
216
  const langColor = primaryLanguage?.color || '#333';
220
- const desc = parseEmojis(description || i18n.t('repocard.no-description'));
217
+ const desc = parseEmojis(description || t.noDescription());
221
218
  const descriptionBoxWidth = card_width - 2 * X_OFFSET;
222
219
 
223
220
  let descriptionLinesCount: number;
@@ -365,9 +362,9 @@ const renderCard = (repo: RepositoryData, options: CardOptions<RepoCardOptions>
365
362
 
366
363
  return card.render([
367
364
  isTemplate
368
- ? getBadgeSVG(i18n.t('repocard.template'), card_width - CARD_DEFAULT_WIDTH)
365
+ ? getBadgeSVG(t.template(), card_width - CARD_DEFAULT_WIDTH)
369
366
  : isArchived
370
- ? getBadgeSVG(i18n.t('repocard.archived'), card_width - CARD_DEFAULT_WIDTH)
367
+ ? getBadgeSVG(t.archived(), card_width - CARD_DEFAULT_WIDTH)
371
368
  : undefined,
372
369
  descriptionSvg,
373
370
  el('g', { transform: `translate(30, ${height - 75 - extraHeight})` }, starAndForkCount),
@@ -0,0 +1,131 @@
1
+ import { defineLocales } from '../../common/localize.ts';
2
+
3
+ /** The repo card's labels in the locales they have been translated into. */
4
+ const repoCardLocales = defineLocales({
5
+ noDescription: {
6
+ en: 'No description provided',
7
+ },
8
+ unspecifiedLanguage: {
9
+ en: 'Unspecified',
10
+ },
11
+ template: {
12
+ en: 'Template',
13
+ ar: 'قالب',
14
+ az: 'Şablon',
15
+ bg: 'Шаблон',
16
+ bn: 'টেমপ্লেট',
17
+ ca: 'Plantilla',
18
+ cn: '模板',
19
+ 'zh-tw': '模板',
20
+ cs: 'Šablona',
21
+ de: 'Vorlage',
22
+ sw: 'Kigezo',
23
+ ur: 'سانچہ',
24
+ es: 'Plantilla',
25
+ fa: 'الگو',
26
+ fi: 'Malli',
27
+ fr: 'Modèle',
28
+ hi: 'खाका',
29
+ sa: 'प्रारूपम्',
30
+ hu: 'Sablon',
31
+ it: 'Template',
32
+ ja: 'テンプレート',
33
+ kr: '템플릿',
34
+ nl: 'Sjabloon',
35
+ 'pt-pt': 'Modelo',
36
+ 'pt-br': 'Modelo',
37
+ np: 'टेम्पलेट',
38
+ el: 'Πρότυπο',
39
+ ro: 'Șablon',
40
+ ru: 'Шаблон',
41
+ 'uk-ua': 'Шаблон',
42
+ id: 'Pola',
43
+ ml: 'ടെംപ്ലേറ്റ്',
44
+ my: 'ပုံစံ',
45
+ ta: `டெம்ப்ளேட்`,
46
+ sk: 'Šablóna',
47
+ tr: 'Şablon',
48
+ pl: 'Szablony',
49
+ uz: 'Shablon',
50
+ vi: 'Mẫu',
51
+ se: 'Mall',
52
+ he: 'תבנית',
53
+ fil: 'Suleras',
54
+ th: 'เทมเพลต',
55
+ sr: 'Шаблон',
56
+ 'sr-latn': 'Šablon',
57
+ no: 'Mal',
58
+ be: 'Шаблон',
59
+ },
60
+ archived: {
61
+ en: 'Archived',
62
+ ar: 'مُؤرشف',
63
+ az: 'Arxiv',
64
+ bg: 'Архивирани',
65
+ bn: 'আর্কাইভড',
66
+ ca: 'Arxivats',
67
+ cn: '已归档',
68
+ 'zh-tw': '已封存',
69
+ cs: 'Archivováno',
70
+ de: 'Archiviert',
71
+ sw: 'Hifadhiwa kwenye kumbukumbu',
72
+ ur: 'محفوظ شدہ',
73
+ es: 'Archivados',
74
+ fa: 'بایگانی‌شده',
75
+ fi: 'Arkistoitu',
76
+ fr: 'Archivé',
77
+ hi: 'संग्रहीत',
78
+ sa: 'संगृहीतम्',
79
+ hu: 'Archivált',
80
+ it: 'Archiviata',
81
+ ja: 'アーカイブ済み',
82
+ kr: '보관됨',
83
+ nl: 'Gearchiveerd',
84
+ 'pt-pt': 'Arquivados',
85
+ 'pt-br': 'Arquivados',
86
+ np: 'अभिलेख राखियो',
87
+ el: 'Αρχειοθετημένα',
88
+ ro: 'Arhivat',
89
+ ru: 'Архивирован',
90
+ 'uk-ua': 'Архивований',
91
+ id: 'Arsip',
92
+ ml: 'ശേഖരിച്ചത്',
93
+ my: 'သိုလှောင်ပြီး',
94
+ ta: `காப்பகப்படுத்தப்பட்டது`,
95
+ sk: 'Archivované',
96
+ tr: 'Arşiv',
97
+ pl: 'Zarchiwizowano',
98
+ uz: 'Arxivlangan',
99
+ vi: 'Đã Lưu Trữ',
100
+ se: 'Arkiverade',
101
+ he: 'גנוז',
102
+ fil: 'Naka-arkibo',
103
+ th: 'เก็บถาวร',
104
+ sr: 'Архивирано',
105
+ 'sr-latn': 'Arhivirano',
106
+ no: 'Arkivert',
107
+ be: 'Архіваваны',
108
+ },
109
+ prsAuthored: {
110
+ en: 'my created PRs',
111
+ 'zh-tw': '我所創建的拉取請求',
112
+ },
113
+ prsCommented: {
114
+ en: 'my commented PRs',
115
+ 'zh-tw': '我所參與的拉取請求',
116
+ },
117
+ prsReviewed: {
118
+ en: 'my reviewed PRs',
119
+ 'zh-tw': '我所審核的拉取請求',
120
+ },
121
+ issuesAuthored: {
122
+ en: 'my created issues',
123
+ 'zh-tw': '我所創建的議題',
124
+ },
125
+ issuesCommented: {
126
+ en: 'my commented issues',
127
+ 'zh-tw': '我所參與的議題',
128
+ },
129
+ });
130
+
131
+ export { repoCardLocales };