@@ -636,33 +636,62 @@ export function useCharts() {
636636 hasEstimation : config . hasEstimation ,
637637 } ) )
638638
639- const granularity = config
640- . $t ( `package.trends.granularity_${ config . granularity } ` )
641- . toLocaleLowerCase ( )
639+ const granularityKeyByGranularity : Record < string , string > = {
640+ daily : 'package.trends.granularity_dayly' ,
641+ weekly : 'package.trends.granularity_weekly' ,
642+ monthly : 'package.trends.granularity_monthly' ,
643+ yearly : 'package.trends.granularity_yearly' ,
644+ }
645+
646+ const granularityKey =
647+ granularityKeyByGranularity [ config . granularity as unknown as string ] ??
648+ 'package.trends.granularity_day'
649+
650+ const granularity = String ( config . $t ( granularityKey ) ) . toLocaleLowerCase ( )
651+
652+ const trendKeyByTrend : Record < string , string > = {
653+ none : 'package.trends.copy_alt.trend_none' ,
654+ weak : 'package.trends.copy_alt.trend_weak' ,
655+ strong : 'package.trends.copy_alt.trend_strong' ,
656+ undefined : 'package.trends.copy_alt.trend_undefined' ,
657+ }
642658
643659 const packages_analysis = analysis
644- . map ( ( pkg , i ) =>
645- config . $t ( `package.trends.copy_alt.analysis` , {
660+ . map ( ( pkg , i ) => {
661+ const trendKey =
662+ trendKeyByTrend [ pkg . interpretation . trend as unknown as string ] ??
663+ 'package.trends.copy_alt.trend_undefined'
664+
665+ return config . $t ( 'package.trends.copy_alt.analysis' , {
646666 package_name : pkg . name ,
647667 start_value : config . formattedDatasetValues [ i ] ?. [ 0 ] ?? 0 ,
648668 end_value : config . formattedDatasetValues [ i ] ?. at ( - 1 ) ?? 0 ,
649- trend : config . $t ( `package.trends.copy_alt.trend_ ${ pkg . interpretation . trend } ` ) ,
669+ trend : config . $t ( trendKey ) ,
650670 downloads_slope : compactNumberFormatter . value . format ( pkg . slope ) ,
651671 growth_percentage : `${ pkg . progressionPercent ?. toFixed ( 1 ) } %` ,
652- } ) ,
653- )
672+ } )
673+ } )
654674 . join ( ', ' )
655675
656676 const isSinglePackage = analysis . length === 1
657677
658678 const estimation_notice = config . hasEstimation
659- ? ` ${ isSinglePackage ? config . $t ( 'package.trends.copy_alt.estimation' ) : config . $t ( 'package.trends.copy_alt.estimations' ) } `
679+ ? ` ${
680+ isSinglePackage
681+ ? config . $t ( 'package.trends.copy_alt.estimation' )
682+ : config . $t ( 'package.trends.copy_alt.estimations' )
683+ } `
660684 : ''
661685
662- // Packages comparison
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` , {
686+ const compareText = `${ config . $t ( 'package.trends.copy_alt.compare' , {
687+ packages : analysis . map ( a => a . name ) . join ( ', ' ) ,
688+ } ) } `
689+
690+ const singlePackageText = `${ config . $t ( 'package.trends.copy_alt.single_package' , {
691+ package : analysis ?. [ 0 ] ?. name ?? '' ,
692+ } ) } `
693+
694+ const generalAnalysis = config . $t ( 'package.trends.copy_alt.general_description' , {
666695 start_date : analysis ?. [ 0 ] ?. dates [ 0 ] ?. text ,
667696 end_date : analysis ?. [ 0 ] ?. dates . at ( - 1 ) ?. text ,
668697 granularity,
0 commit comments