File tree Expand file tree Collapse file tree
packages/ui/src/composables Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { LRUCache } from 'lru-cache'
22
33import { injectI18n } from '../providers/i18n'
4+ import { LOCALES } from './i18n.ts'
45
56const formatterCache = new LRUCache < string , Intl . NumberFormat > ( { max : 15 } )
67
@@ -35,16 +36,13 @@ export function useCompactNumber() {
3536 return twoDigitsCompactFormatter . format ( value )
3637 }
3738
38- function formatCompactNumberPlural ( value : number | bigint ) : string {
39+ function formatCompactNumberPlural ( value : number | bigint ) : number | bigint {
3940 if ( value < 10_000 ) {
40- return value . toString ( )
41+ return value
4142 }
42- if ( value < 1_000_000 ) {
43- const oneDigitCompactFormatter = getCompactFormatter ( locale . value , 1 )
44- return oneDigitCompactFormatter . format ( value )
45- }
46- const twoDigitsCompactFormatter = getCompactFormatter ( locale . value , 2 )
47- return twoDigitsCompactFormatter . format ( value )
43+ const currentLocale = locale . value
44+ const localeDefinition = LOCALES . find ( ( l ) => l . code === currentLocale )
45+ return localeDefinition ?. compactNumberPlural ?? NaN
4846 }
4947
5048 return { formatCompactNumber, formatCompactNumberPlural }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ export interface LocaleDefinition {
3030 name : string
3131 translatedName : MessageDescriptor
3232 numeric ?: Intl . RelativeTimeFormatNumeric
33+ compactNumberPlural ?: number
3334 dir ?: 'ltr' | 'rtl'
3435 serverLanguageCode ?: string
3536}
@@ -92,6 +93,7 @@ export const LOCALES: LocaleDefinition[] = [
9293 code : 'fil-PH' ,
9394 name : 'Filipino' ,
9495 translatedName : defineMessage ( { id : 'locale.fil-PH' , defaultMessage : 'Filipino' } ) ,
96+ compactNumberPlural : 1 ,
9597 serverLanguageCode : 'tl' ,
9698 } ,
9799 {
You can’t perform that action at this time.
0 commit comments