Skip to content

Commit c6e367f

Browse files
committed
fix: pass translate function from the component
1 parent 04f27ff commit c6e367f

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

app/components/Package/TrendsChart.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ const chartConfig = computed<VueUiXyConfig>(() => {
14731473
supportsEstimation.value && !isEndDateOnPeriodEnd.value && !isZoomed.value,
14741474
granularity: displayedGranularity.value,
14751475
copy,
1476+
$t,
14761477
},
14771478
}),
14781479
},

app/composables/useCharts.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ export function useCharts() {
627627
dataset,
628628
config,
629629
}: AltCopyArgs<TrendLineDataset, TrendLineConfig>): string {
630-
const { t } = useI18n()
631630
if (!dataset) return ''
632631

633632
const analysis = dataset.lines.map(({ name, series }) => ({
@@ -637,15 +636,17 @@ export function useCharts() {
637636
hasEstimation: config.hasEstimation,
638637
}))
639638

640-
const granularity = t(`package.trends.granularity_${config.granularity}`).toLocaleLowerCase()
639+
const granularity = config
640+
.$t(`package.trends.granularity_${config.granularity}`)
641+
.toLocaleLowerCase()
641642

642643
const packages_analysis = analysis
643644
.map((pkg, i) =>
644-
t(`package.trends.copy_alt.analysis`, {
645+
config.$t(`package.trends.copy_alt.analysis`, {
645646
package_name: pkg.name,
646647
start_value: config.formattedDatasetValues[i]?.[0] ?? 0,
647648
end_value: config.formattedDatasetValues[i]?.at(-1) ?? 0,
648-
trend: t(`package.trends.copy_alt.trend_${pkg.interpretation.trend}`),
649+
trend: config.$t(`package.trends.copy_alt.trend_${pkg.interpretation.trend}`),
649650
downloads_slope: compactNumberFormatter.value.format(pkg.slope),
650651
growth_percentage: `${pkg.progressionPercent?.toFixed(1)}%`,
651652
}),
@@ -655,18 +656,18 @@ export function useCharts() {
655656
const isSinglePackage = analysis.length === 1
656657

657658
const estimation_notice = config.hasEstimation
658-
? ` ${isSinglePackage ? t('package.trends.copy_alt.estimation') : t('package.trends.copy_alt.estimations')}`
659+
? ` ${isSinglePackage ? config.$t('package.trends.copy_alt.estimation') : config.$t('package.trends.copy_alt.estimations')}`
659660
: ''
660661

661662
// Packages comparison
662-
const compareText = `${t('package.trends.copy_alt.compare', { packages: analysis.map(a => a.name).join(', ') })} `
663-
const singlePackageText = `${t('package.trends.copy_alt.single_package', { package: analysis?.[0]?.name ?? '' })} `
664-
const generalAnalysis = t(`package.trends.copy_alt.general_description`, {
663+
const compareText = `${config.$t('package.trends.copy_alt.compare', { packages: analysis.map(a => a.name).join(', ') })} `
664+
const singlePackageText = `${config.$t('package.trends.copy_alt.single_package', { package: analysis?.[0]?.name ?? '' })} `
665+
const generalAnalysis = config.$t(`package.trends.copy_alt.general_description`, {
665666
start_date: analysis?.[0]?.dates[0]?.text,
666667
end_date: analysis?.[0]?.dates.at(-1)?.text,
667668
granularity,
668669
packages_analysis,
669-
watermark: t('package.trends.copy_alt.watermark'),
670+
watermark: config.$t('package.trends.copy_alt.watermark'),
670671
estimation_notice,
671672
})
672673

app/utils/charts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,5 @@ export type TrendLineConfig = VueUiXyConfig & {
487487
formattedDatasetValues: Array<string[]>
488488
granularity: ChartTimeGranularity // from the TrendsChart component
489489
copy: (text: string) => Promise<void>
490+
$t: TrendTranslateFunction
490491
}

0 commit comments

Comments
 (0)