@@ -30,7 +30,10 @@ export interface PackageComparisonData {
3030 *
3131 * @public
3232 */
33- export function usePackageComparison ( packageNames : MaybeRefOrGetter < string [ ] > ) {
33+ export function usePackageComparison (
34+ packageNames : MaybeRefOrGetter < string [ ] > ,
35+ t : ( key : string , params ?: Record < string , unknown > ) => string = key => key ,
36+ ) {
3437 const packages = computed ( ( ) => toValue ( packageNames ) )
3538
3639 // Cache of fetched data by package name (source of truth)
@@ -196,7 +199,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
196199
197200 return packagesData . value . map ( pkg => {
198201 if ( ! pkg ) return null
199- return computeFacetValue ( facet , pkg )
202+ return computeFacetValue ( facet , pkg , t )
200203 } )
201204 }
202205
@@ -230,7 +233,11 @@ function encodePackageName(name: string): string {
230233 return encodeURIComponent ( name )
231234}
232235
233- function computeFacetValue ( facet : ComparisonFacet , data : PackageComparisonData ) : FacetValue | null {
236+ function computeFacetValue (
237+ facet : ComparisonFacet ,
238+ data : PackageComparisonData ,
239+ t : ( key : string , params ?: Record < string , unknown > ) => string ,
240+ ) : FacetValue | null {
234241 switch ( facet ) {
235242 case 'downloads' :
236243 if ( data . downloads === undefined ) return null
@@ -271,13 +278,19 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
271278 return {
272279 raw : types . kind ,
273280 display :
274- types . kind === 'included' ? 'Included' : types . kind === '@types' ? '@types' : 'None' ,
281+ types . kind === 'included'
282+ ? t ( 'compare.facets.values.types_included' )
283+ : types . kind === '@types'
284+ ? '@types'
285+ : t ( 'compare.facets.values.types_none' ) ,
275286 status : types . kind === 'included' ? 'good' : types . kind === '@types' ? 'info' : 'bad' ,
276287 }
277288
278289 case 'engines' :
279290 const engines = data . metadata ?. engines
280- if ( ! engines ?. node ) return { raw : null , display : 'Any' , status : 'neutral' }
291+ if ( ! engines ?. node ) {
292+ return { raw : null , display : t ( 'compare.facets.values.any' ) , status : 'neutral' }
293+ }
281294 return {
282295 raw : engines . node ,
283296 display : `Node ${ engines . node } ` ,
@@ -290,7 +303,14 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
290303 const sev = data . vulnerabilities . severity
291304 return {
292305 raw : count ,
293- display : count === 0 ? 'None' : `${ count } (${ sev . critical } C/${ sev . high } H)` ,
306+ display :
307+ count === 0
308+ ? t ( 'compare.facets.values.none' )
309+ : t ( 'compare.facets.values.vulnerabilities_summary' , {
310+ count,
311+ critical : sev . critical ,
312+ high : sev . high ,
313+ } ) ,
294314 status : count === 0 ? 'good' : sev . critical > 0 || sev . high > 0 ? 'bad' : 'warning' ,
295315 }
296316
@@ -306,7 +326,9 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
306326
307327 case 'license' :
308328 const license = data . metadata ?. license
309- if ( ! license ) return { raw : null , display : 'Unknown' , status : 'warning' }
329+ if ( ! license ) {
330+ return { raw : null , display : t ( 'compare.facets.values.unknown' ) , status : 'warning' }
331+ }
310332 return {
311333 raw : license ,
312334 display : license ,
@@ -326,7 +348,9 @@ function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData):
326348 const isDeprecated = ! ! data . metadata ?. deprecated
327349 return {
328350 raw : isDeprecated ,
329- display : isDeprecated ? 'Deprecated' : 'No' ,
351+ display : isDeprecated
352+ ? t ( 'compare.facets.values.deprecated' )
353+ : t ( 'compare.facets.values.not_deprecated' ) ,
330354 status : isDeprecated ? 'bad' : 'good' ,
331355 }
332356
0 commit comments