Skip to content

Commit e8665f4

Browse files
JerozgenIMB11
andauthored
Filipino compact number plural rule (#5516)
Use `one` for compact numbers in Filipino Signed-off-by: Jerozgen <jerozgen@gmail.com> Co-authored-by: Calum H. <calum@modrinth.com>
1 parent cba4550 commit e8665f4

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

packages/ui/src/composables/format-number.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LRUCache } from 'lru-cache'
22

33
import { injectI18n } from '../providers/i18n'
4+
import { LOCALES } from './i18n.ts'
45

56
const 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 }

packages/ui/src/composables/i18n.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)