Skip to content

Commit e8cf652

Browse files
committed
refactor: generalize i18n keys for download trends
I've been working on a PR to add "likes" as a new facet that can be visualized in what I'm calling "trends" charts (e.g. downloads over time, likes over time). That PR generalizes the existing "downloads" chart to support one or more given facets. I've had a half dozen painful merge conflicts across 37 locale files, so I've pulled out just this i18n key rename into its own PR to make this all easier.
1 parent 4564479 commit e8cf652

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+739
-644
lines changed

app/components/Package/DownloadAnalytics.vue

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,28 @@ function extractSeriesPoints(
261261
dataset: EvolutionData,
262262
): Array<{ timestamp: number; downloads: number }> {
263263
if (selectedGranularity === 'weekly' && isWeeklyDataset(dataset)) {
264-
return dataset.map(d => ({ timestamp: d.timestampEnd, downloads: d.downloads }))
264+
return dataset.map(d => ({
265+
timestamp: d.timestampEnd,
266+
downloads: d.downloads,
267+
}))
265268
}
266269
if (selectedGranularity === 'daily' && isDailyDataset(dataset)) {
267-
return dataset.map(d => ({ timestamp: d.timestamp, downloads: d.downloads }))
270+
return dataset.map(d => ({
271+
timestamp: d.timestamp,
272+
downloads: d.downloads,
273+
}))
268274
}
269275
if (selectedGranularity === 'monthly' && isMonthlyDataset(dataset)) {
270-
return dataset.map(d => ({ timestamp: d.timestamp, downloads: d.downloads }))
276+
return dataset.map(d => ({
277+
timestamp: d.timestamp,
278+
downloads: d.downloads,
279+
}))
271280
}
272281
if (selectedGranularity === 'yearly' && isYearlyDataset(dataset)) {
273-
return dataset.map(d => ({ timestamp: d.timestamp, downloads: d.downloads }))
282+
return dataset.map(d => ({
283+
timestamp: d.timestamp,
284+
downloads: d.downloads,
285+
}))
274286
}
275287
return []
276288
}
@@ -493,7 +505,12 @@ function resetDateRange() {
493505
const options = shallowRef<
494506
| { granularity: 'day'; startDate?: string; endDate?: string }
495507
| { granularity: 'week'; weeks: number; startDate?: string; endDate?: string }
496-
| { granularity: 'month'; months: number; startDate?: string; endDate?: string }
508+
| {
509+
granularity: 'month'
510+
months: number
511+
startDate?: string
512+
endDate?: string
513+
}
497514
| { granularity: 'year'; startDate?: string; endDate?: string }
498515
>({ granularity: 'week', weeks: 52 })
499516
@@ -743,7 +760,10 @@ const effectiveDataSingle = computed<EvolutionData>(() => {
743760
* Returning `dataset: null` explicitly signals the absence of data and allows
744761
* the template to handle empty states without ambiguity.
745762
*/
746-
const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: number[] }>(() => {
763+
const chartData = computed<{
764+
dataset: VueUiXyDatasetItem[] | null
765+
dates: number[]
766+
}>(() => {
747767
if (!isMultiPackageMode.value) {
748768
const pkg = effectivePackageNames.value[0] ?? props.packageName ?? ''
749769
return formatXyDataset(displayedGranularity.value, effectiveDataSingle.value, pkg)
@@ -772,7 +792,11 @@ const chartData = computed<{ dataset: VueUiXyDatasetItem[] | null; dates: number
772792
773793
const series = dates.map(t => map.get(t) ?? 0)
774794
775-
const item: VueUiXyDatasetItem = { name: pkg, type: 'line', series } as VueUiXyDatasetItem
795+
const item: VueUiXyDatasetItem = {
796+
name: pkg,
797+
type: 'line',
798+
series,
799+
} as VueUiXyDatasetItem
776800
777801
if (isListedFramework(pkg)) {
778802
item.color = getFrameworkColor(pkg)
@@ -895,10 +919,10 @@ function buildExportFilename(extension: string): string {
895919
}
896920
897921
const granularityLabels = computed(() => ({
898-
daily: $t('package.downloads.granularity_daily'),
899-
weekly: $t('package.downloads.granularity_weekly'),
900-
monthly: $t('package.downloads.granularity_monthly'),
901-
yearly: $t('package.downloads.granularity_yearly'),
922+
daily: $t('package.trends.granularity_daily'),
923+
weekly: $t('package.trends.granularity_weekly'),
924+
monthly: $t('package.trends.granularity_monthly'),
925+
yearly: $t('package.trends.granularity_yearly'),
902926
}))
903927
904928
function getGranularityLabel(granularity: ChartTimeGranularity) {
@@ -1102,7 +1126,11 @@ function extrapolateIncompleteLastPoint(params: {
11021126
const yDelta = params.lastPoint.y - params.previousPoint.y
11031127
11041128
if (valueDelta === 0)
1105-
return { ...params.lastPoint, value: extrapolatedValue, comment: 'extrapolated' }
1129+
return {
1130+
...params.lastPoint,
1131+
value: extrapolatedValue,
1132+
comment: 'extrapolated',
1133+
}
11061134
11071135
const valueToYPixelRatio = yDelta / valueDelta
11081136
const extrapolatedY =
@@ -1319,20 +1347,26 @@ const chartConfig = computed(() => {
13191347
backgroundColor: colors.value.bg,
13201348
padding: { bottom: 36, right: 100 }, // padding right is set to leave space of last datapoint label(s)
13211349
userOptions: {
1322-
buttons: { pdf: false, labels: false, fullscreen: false, table: false, tooltip: false },
1350+
buttons: {
1351+
pdf: false,
1352+
labels: false,
1353+
fullscreen: false,
1354+
table: false,
1355+
tooltip: false,
1356+
},
13231357
buttonTitles: {
1324-
csv: $t('package.downloads.download_file', { fileType: 'CSV' }),
1325-
img: $t('package.downloads.download_file', { fileType: 'PNG' }),
1326-
svg: $t('package.downloads.download_file', { fileType: 'SVG' }),
1327-
annotator: $t('package.downloads.toggle_annotator'),
1358+
csv: $t('package.trends.download_file', { fileType: 'CSV' }),
1359+
img: $t('package.trends.download_file', { fileType: 'PNG' }),
1360+
svg: $t('package.trends.download_file', { fileType: 'SVG' }),
1361+
annotator: $t('package.trends.toggle_annotator'),
13281362
},
13291363
callbacks: {
13301364
img: ({ imageUri }: { imageUri: string }) => {
13311365
loadFile(imageUri, buildExportFilename('png'))
13321366
},
13331367
csv: (csvStr: string) => {
13341368
const PLACEHOLDER_CHAR = '\0'
1335-
const multilineDateTemplate = $t('package.downloads.date_range_multiline', {
1369+
const multilineDateTemplate = $t('package.trends.date_range_multiline', {
13361370
start: PLACEHOLDER_CHAR,
13371371
end: PLACEHOLDER_CHAR,
13381372
})
@@ -1360,8 +1394,9 @@ const chartConfig = computed(() => {
13601394
fontSize: isMobile.value ? 24 : 16,
13611395
color: pending.value ? colors.value.border : colors.value.fgSubtle,
13621396
axis: {
1363-
yLabel: $t('package.downloads.y_axis_label', {
1397+
yLabel: $t('package.trends.y_axis_label', {
13641398
granularity: getGranularityLabel(selectedGranularity.value),
1399+
facet: $t('package.trends.items.downloads'),
13651400
}),
13661401
xLabel: isMultiPackageMode.value ? '' : xAxisLabel.value, // for multiple series, names are displayed in the chart's legend
13671402
yLabelOffsetX: 12,
@@ -1478,7 +1513,7 @@ const chartConfig = computed(() => {
14781513
for="granularity"
14791514
class="text-3xs font-mono text-fg-subtle tracking-wide uppercase"
14801515
>
1481-
{{ $t('package.downloads.granularity') }}
1516+
{{ $t('package.trends.granularity') }}
14821517
</label>
14831518

14841519
<div
@@ -1490,10 +1525,18 @@ const chartConfig = computed(() => {
14901525
:disabled="pending"
14911526
class="w-full px-2.5 py-1.75 bg-bg-subtle font-mono text-sm text-fg outline-none appearance-none focus-visible:outline-accent/70"
14921527
>
1493-
<option value="daily">{{ $t('package.downloads.granularity_daily') }}</option>
1494-
<option value="weekly">{{ $t('package.downloads.granularity_weekly') }}</option>
1495-
<option value="monthly">{{ $t('package.downloads.granularity_monthly') }}</option>
1496-
<option value="yearly">{{ $t('package.downloads.granularity_yearly') }}</option>
1528+
<option value="daily">
1529+
{{ $t('package.trends.granularity_daily') }}
1530+
</option>
1531+
<option value="weekly">
1532+
{{ $t('package.trends.granularity_weekly') }}
1533+
</option>
1534+
<option value="monthly">
1535+
{{ $t('package.trends.granularity_monthly') }}
1536+
</option>
1537+
<option value="yearly">
1538+
{{ $t('package.trends.granularity_yearly') }}
1539+
</option>
14971540
</select>
14981541
</div>
14991542
</div>
@@ -1504,7 +1547,7 @@ const chartConfig = computed(() => {
15041547
for="startDate"
15051548
class="text-3xs font-mono text-fg-subtle tracking-wide uppercase"
15061549
>
1507-
{{ $t('package.downloads.start_date') }}
1550+
{{ $t('package.trends.start_date') }}
15081551
</label>
15091552
<div
15101553
class="flex items-center gap-2 px-2.5 py-1.75 bg-bg-subtle border border-border rounded-md focus-within:(border-border-hover ring-2 ring-accent/70)"
@@ -1522,7 +1565,7 @@ const chartConfig = computed(() => {
15221565

15231566
<div class="flex flex-col gap-1">
15241567
<label for="endDate" class="text-3xs font-mono text-fg-subtle tracking-wide uppercase">
1525-
{{ $t('package.downloads.end_date') }}
1568+
{{ $t('package.trends.end_date') }}
15261569
</label>
15271570
<div
15281571
class="flex items-center gap-2 px-2.5 py-1.75 bg-bg-subtle border border-border rounded-md focus-within:(border-border-hover ring-2 ring-accent/70)"
@@ -1656,9 +1699,7 @@ const chartConfig = computed(() => {
16561699
stroke-linecap="round"
16571700
/>
16581701
</svg>
1659-
<span class="text-fg-subtle">{{
1660-
$t('package.downloads.legend_estimation')
1661-
}}</span>
1702+
<span class="text-fg-subtle">{{ $t('package.trends.legend_estimation') }}</span>
16621703
</div>
16631704
</div>
16641705
</template>
@@ -1747,7 +1788,11 @@ const chartConfig = computed(() => {
17471788
v-if="!chartData.dataset && !pending"
17481789
class="min-h-[260px] flex items-center justify-center text-fg-subtle font-mono text-sm"
17491790
>
1750-
{{ $t('package.downloads.no_data') }}
1791+
{{
1792+
$t('package.trends.no_data', {
1793+
facet: $t('package.trends.items.downloads'),
1794+
})
1795+
}}
17511796
</div>
17521797

17531798
<div
@@ -1756,7 +1801,7 @@ const chartConfig = computed(() => {
17561801
aria-live="polite"
17571802
class="absolute top-1/2 inset-is-1/2 -translate-x-1/2 -translate-y-1/2 text-xs text-fg-subtle font-mono bg-bg/70 backdrop-blur px-3 py-2 rounded-md border border-border"
17581803
>
1759-
{{ $t('package.downloads.loading') }}
1804+
{{ $t('package.trends.loading') }}
17601805
</div>
17611806
</div>
17621807
</template>

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ watch(
124124
const dataset = computed(() =>
125125
weeklyDownloads.value.map(d => ({
126126
value: d?.downloads ?? 0,
127-
period: $t('package.downloads.date_range', {
127+
period: $t('package.trends.date_range', {
128128
start: d.weekStart ?? '-',
129129
end: d.weekEnd ?? '-',
130130
}),

app/pages/compare.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ useSeoMeta({
242242
id="comparison-heading"
243243
class="text-xs text-fg-subtle uppercase tracking-wider mb-4 mt-10"
244244
>
245-
{{ $t('package.downloads.title') }}
245+
{{ $t('compare.facets.trends.title') }}
246246
</h2>
247247

248248
<CompareLineChart :packages="packages.filter(p => p !== NO_DEPENDENCY_ID)" />

i18n/locales/ar.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,9 @@
284284
},
285285
"downloads": {
286286
"title": "التنزيلات الأسبوعية",
287-
"date_range": "من {start} إلى {end}",
288-
"date_range_multiline": "من {start}\nإلى {end}",
289287
"analyze": "تحليل التنزيلات",
290288
"community_distribution": "عرض توزيع تبنّي المجتمع",
291-
"modal_title": "التنزيلات",
292-
"granularity": "مستوى التفصيل",
293-
"granularity_daily": "يومي",
294-
"granularity_weekly": "أسبوعي",
295-
"granularity_monthly": "شهري",
296-
"granularity_yearly": "سنوي",
297-
"start_date": "البداية",
298-
"end_date": "النهاية",
299-
"no_data": "لا تتوفر بيانات تنزيل",
300-
"loading": "جارٍ التحميل…",
301-
"y_axis_label": "تنزيلات {granularity}ة",
302-
"download_file": "تنزيل {fileType}",
303-
"toggle_annotator": "إظهار/إخفاء الشروح التوضيحية"
289+
"modal_title": "التنزيلات"
304290
},
305291
"install_scripts": {
306292
"title": "سكربتات التثبيت",
@@ -384,6 +370,20 @@
384370
"published": "الأحدث نشرًا",
385371
"name_asc": "الاسم (A-Z)",
386372
"name_desc": "الاسم (Z-A)"
373+
},
374+
"trends": {
375+
"granularity": "مستوى التفصيل",
376+
"granularity_daily": "يومي",
377+
"granularity_weekly": "أسبوعي",
378+
"granularity_monthly": "شهري",
379+
"granularity_yearly": "سنوي",
380+
"start_date": "البداية",
381+
"end_date": "النهاية",
382+
"loading": "جارٍ التحميل…",
383+
"date_range": "من {start} إلى {end}",
384+
"date_range_multiline": "من {start}\nإلى {end}",
385+
"download_file": "تنزيل {fileType}",
386+
"toggle_annotator": "إظهار/إخفاء الشروح التوضيحية"
387387
}
388388
},
389389
"connector": {

i18n/locales/az-AZ.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,8 @@
219219
},
220220
"downloads": {
221221
"title": "Həftəlik Endirmələr",
222-
"date_range": "{start} - {end}",
223-
"date_range_multiline": "{start}\n- {end}",
224222
"analyze": "Endirmələri təhlil et",
225-
"modal_title": "Endirmələr",
226-
"granularity": "Dərəcəlilik",
227-
"granularity_daily": "Günlük",
228-
"granularity_weekly": "Həftəlik",
229-
"granularity_monthly": "Aylıq",
230-
"granularity_yearly": "İllik",
231-
"start_date": "Başlanğıc",
232-
"end_date": "Son",
233-
"no_data": "Endirmə məlumatı mövcud deyil",
234-
"loading": "Yüklənir...",
235-
"y_axis_label": "{granularity} endirmələr",
236-
"download_file": "{fileType} endir",
237-
"toggle_annotator": "Annotator keçid"
223+
"modal_title": "Endirmələr"
238224
},
239225
"install_scripts": {
240226
"title": "Quraşdırma Skriptləri",
@@ -315,6 +301,20 @@
315301
"downloads": "Ən çox endirilən",
316302
"name_asc": "Ad (A-Z)",
317303
"name_desc": "Ad (Z-A)"
304+
},
305+
"trends": {
306+
"granularity": "Dərəcəlilik",
307+
"granularity_daily": "Günlük",
308+
"granularity_weekly": "Həftəlik",
309+
"granularity_monthly": "Aylıq",
310+
"granularity_yearly": "İllik",
311+
"start_date": "Başlanğıc",
312+
"end_date": "Son",
313+
"loading": "Yüklənir...",
314+
"date_range": "{start} - {end}",
315+
"date_range_multiline": "{start}\n- {end}",
316+
"download_file": "{fileType} endir",
317+
"toggle_annotator": "Annotator keçid"
318318
}
319319
},
320320
"connector": {

i18n/locales/cs-CZ.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,8 @@
254254
},
255255
"downloads": {
256256
"title": "Týdenní stažení",
257-
"date_range": "od {start} do {end}",
258-
"date_range_multiline": "od {start}\ndo {end}",
259257
"analyze": "Analyzovat stažení",
260-
"modal_title": "Stažení",
261-
"granularity": "Rozlišení",
262-
"granularity_daily": "Denně",
263-
"granularity_weekly": "Týdně",
264-
"granularity_monthly": "Měsíčně",
265-
"granularity_yearly": "Ročně",
266-
"start_date": "Od",
267-
"end_date": "Do",
268-
"no_data": "Žádná data o stažení nejsou k dispozici",
269-
"loading": "Načítání...",
270-
"y_axis_label": "Stažení {granularity}",
271-
"download_file": "Stáhnout {fileType}",
272-
"toggle_annotator": "Přepnout popisovač"
258+
"modal_title": "Stažení"
273259
},
274260
"install_scripts": {
275261
"title": "Instalační skripty",
@@ -353,6 +339,20 @@
353339
"published": "Nedávno publikováno",
354340
"name_asc": "Název (A-Z)",
355341
"name_desc": "Název (Z-A)"
342+
},
343+
"trends": {
344+
"granularity": "Rozlišení",
345+
"granularity_daily": "Denně",
346+
"granularity_weekly": "Týdně",
347+
"granularity_monthly": "Měsíčně",
348+
"granularity_yearly": "Ročně",
349+
"start_date": "Od",
350+
"end_date": "Do",
351+
"loading": "Načítání...",
352+
"date_range": "od {start} do {end}",
353+
"date_range_multiline": "od {start}\ndo {end}",
354+
"download_file": "Stáhnout {fileType}",
355+
"toggle_annotator": "Přepnout popisovač"
356356
}
357357
},
358358
"connector": {

0 commit comments

Comments
 (0)