@@ -29,7 +29,10 @@ export interface PackageComparisonData {
2929 * Composable for fetching and comparing multiple packages.
3030 *
3131 */
32- export function usePackageComparison ( packageNames : MaybeRefOrGetter < string [ ] > ) {
32+ export function usePackageComparison (
33+ packageNames : MaybeRefOrGetter < string [ ] > ,
34+ t : ( key : string , params ?: Record < string , unknown > ) => string = key => key ,
35+ ) {
3336 const packages = computed ( ( ) => toValue ( packageNames ) )
3437
3538 // Cache of fetched data by package name (source of truth)
@@ -195,7 +198,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
195198
196199 return packagesData . value . map ( pkg => {
197200 if ( ! pkg ) return null
198- return computeFacetValue ( facet , pkg )
201+ return computeFacetValue ( facet , pkg , t )
199202 } )
200203 }
201204
@@ -229,7 +232,11 @@ function encodePackageName(name: string): string {
229232 return encodeURIComponent ( name )
230233}
231234
232- function computeFacetValue ( facet : ComparisonFacet , data : PackageComparisonData ) : FacetValue | null {
235+ function computeFacetValue (
236+ facet : ComparisonFacet ,
237+ data : PackageComparisonData ,
238+ t : ( key : string , params ?: Record < string , unknown > ) => string ,
239+ ) : FacetValue | null {
233240 switch ( facet ) {
234241 case 'downloads' :
235242 if ( data . downloads === undefined ) return null
@@ -270,13 +277,19 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
270277 return {
271278 raw : types . kind ,
272279 display :
273- types . kind === 'included' ? 'Included' : types . kind === '@types' ? '@types' : 'None' ,
280+ types . kind === 'included'
281+ ? t ( 'compare.facets.values.types_included' )
282+ : types . kind === '@types'
283+ ? '@types'
284+ : t ( 'compare.facets.values.types_none' ) ,
274285 status : types . kind === 'included' ? 'good' : types . kind === '@types' ? 'info' : 'bad' ,
275286 }
276287
277288 case 'engines' :
278289 const engines = data . metadata ?. engines
279- if ( ! engines ?. node ) return { raw : null , display : 'Any' , status : 'neutral' }
290+ if ( ! engines ?. node ) {
291+ return { raw : null , display : t ( 'compare.facets.values.any' ) , status : 'neutral' }
292+ }
280293 return {
281294 raw : engines . node ,
282295 display : `Node ${ engines . node } ` ,
@@ -289,7 +302,14 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
289302 const sev = data . vulnerabilities . severity
290303 return {
291304 raw : count ,
292- display : count === 0 ? 'None' : `${ count } (${ sev . critical } C/${ sev . high } H)` ,
305+ display :
306+ count === 0
307+ ? t ( 'compare.facets.values.none' )
308+ : t ( 'compare.facets.values.vulnerabilities_summary' , {
309+ count,
310+ critical : sev . critical ,
311+ high : sev . high ,
312+ } ) ,
293313 status : count === 0 ? 'good' : sev . critical > 0 || sev . high > 0 ? 'bad' : 'warning' ,
294314 }
295315
@@ -305,7 +325,9 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
305325
306326 case 'license' :
307327 const license = data . metadata ?. license
308- if ( ! license ) return { raw : null , display : 'Unknown' , status : 'warning' }
328+ if ( ! license ) {
329+ return { raw : null , display : t ( 'compare.facets.values.unknown' ) , status : 'warning' }
330+ }
309331 return {
310332 raw : license ,
311333 display : license ,
@@ -325,7 +347,9 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
325347 const isDeprecated = ! ! data . metadata ?. deprecated
326348 return {
327349 raw : isDeprecated ,
328- display : isDeprecated ? 'Deprecated' : 'No' ,
350+ display : isDeprecated
351+ ? t ( 'compare.facets.values.deprecated' )
352+ : t ( 'compare.facets.values.not_deprecated' ) ,
329353 status : isDeprecated ? 'bad' : 'good' ,
330354 }
331355
0 commit comments