@@ -15,7 +15,6 @@ import {
1515 DEFAULT_FILTERS ,
1616 DOWNLOAD_RANGES ,
1717 parseSortOption ,
18- SECURITY_FILTER_OPTIONS ,
1918 UPDATED_WITHIN_OPTIONS ,
2019} from '#shared/types/preferences'
2120
@@ -114,6 +113,7 @@ function matchesSecurity(pkg: NpmSearchResult, security: SecurityFilter): boolea
114113 */
115114export function useStructuredFilters ( options : UseStructuredFiltersOptions ) {
116115 const { packages, initialFilters, initialSort } = options
116+ const { t } = useI18n ( )
117117
118118 // Filter state
119119 const filters = ref < StructuredFilters > ( {
@@ -292,6 +292,30 @@ export function useStructuredFilters(options: UseStructuredFiltersOptions) {
292292 return [ ...filteredPackages . value ] . sort ( ( a , b ) => comparePackages ( a , b , sortOption . value ) )
293293 } )
294294
295+ // i18n key mappings for filter chip values
296+ const downloadRangeKeys : Record < DownloadRange , string > = {
297+ 'any' : 'filters.download_range.any' ,
298+ 'lt100' : 'filters.download_range.lt100' ,
299+ '100-1k' : 'filters.download_range.100_1k' ,
300+ '1k-10k' : 'filters.download_range.1k_10k' ,
301+ '10k-100k' : 'filters.download_range.10k_100k' ,
302+ 'gt100k' : 'filters.download_range.gt100k' ,
303+ }
304+
305+ const securityKeys : Record < SecurityFilter , string > = {
306+ all : 'filters.security_options.all' ,
307+ secure : 'filters.security_options.secure' ,
308+ warnings : 'filters.security_options.insecure' ,
309+ }
310+
311+ const updatedWithinKeys : Record < UpdatedWithin , string > = {
312+ any : 'filters.updated.any' ,
313+ week : 'filters.updated.week' ,
314+ month : 'filters.updated.month' ,
315+ quarter : 'filters.updated.quarter' ,
316+ year : 'filters.updated.year' ,
317+ }
318+
295319 // Active filter chips for display
296320 const activeFilters = computed < FilterChip [ ] > ( ( ) => {
297321 const chips : FilterChip [ ] = [ ]
@@ -300,47 +324,44 @@ export function useStructuredFilters(options: UseStructuredFiltersOptions) {
300324 chips . push ( {
301325 id : 'text' ,
302326 type : 'text' ,
303- label : 'Search' ,
327+ label : t ( 'filters.chips.search' ) ,
304328 value : filters . value . text ,
305329 } )
306330 }
307331
308332 if ( filters . value . downloadRange !== 'any' ) {
309- const config = DOWNLOAD_RANGES . find ( r => r . value === filters . value . downloadRange )
310333 chips . push ( {
311334 id : 'downloadRange' ,
312335 type : 'downloadRange' ,
313- label : 'Downloads' ,
314- value : config ?. label ?? filters . value . downloadRange ,
336+ label : t ( 'filters.chips.downloads' ) ,
337+ value : t ( downloadRangeKeys [ filters . value . downloadRange ] ) ,
315338 } )
316339 }
317340
318341 for ( const keyword of filters . value . keywords ) {
319342 chips . push ( {
320343 id : `keyword-${ keyword } ` ,
321344 type : 'keywords' ,
322- label : 'Keyword' ,
345+ label : t ( 'filters.chips.keyword' ) ,
323346 value : keyword ,
324347 } )
325348 }
326349
327350 if ( filters . value . security !== 'all' ) {
328- const config = SECURITY_FILTER_OPTIONS . find ( o => o . value === filters . value . security )
329351 chips . push ( {
330352 id : 'security' ,
331353 type : 'security' ,
332- label : 'Security' ,
333- value : config ?. label ?? filters . value . security ,
354+ label : t ( 'filters.chips.security' ) ,
355+ value : t ( securityKeys [ filters . value . security ] ) ,
334356 } )
335357 }
336358
337359 if ( filters . value . updatedWithin !== 'any' ) {
338- const config = UPDATED_WITHIN_OPTIONS . find ( o => o . value === filters . value . updatedWithin )
339360 chips . push ( {
340361 id : 'updatedWithin' ,
341362 type : 'updatedWithin' ,
342- label : 'Updated' ,
343- value : config ?. label ?? filters . value . updatedWithin ,
363+ label : t ( 'filters.chips.updated' ) ,
364+ value : t ( updatedWithinKeys [ filters . value . updatedWithin ] ) ,
344365 } )
345366 }
346367
0 commit comments