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>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { LRUCache } from 'lru-cache'
|
import { LRUCache } from 'lru-cache'
|
||||||
|
|
||||||
import { injectI18n } from '../providers/i18n'
|
import { injectI18n } from '../providers/i18n'
|
||||||
|
import { LOCALES } from './i18n.ts'
|
||||||
|
|
||||||
const formatterCache = new LRUCache<string, Intl.NumberFormat>({ max: 15 })
|
const formatterCache = new LRUCache<string, Intl.NumberFormat>({ max: 15 })
|
||||||
|
|
||||||
@@ -35,16 +36,13 @@ export function useCompactNumber() {
|
|||||||
return twoDigitsCompactFormatter.format(value)
|
return twoDigitsCompactFormatter.format(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCompactNumberPlural(value: number | bigint): string {
|
function formatCompactNumberPlural(value: number | bigint): number | bigint {
|
||||||
if (value < 10_000) {
|
if (value < 10_000) {
|
||||||
return value.toString()
|
return value
|
||||||
}
|
}
|
||||||
if (value < 1_000_000) {
|
const currentLocale = locale.value
|
||||||
const oneDigitCompactFormatter = getCompactFormatter(locale.value, 1)
|
const localeDefinition = LOCALES.find((l) => l.code === currentLocale)
|
||||||
return oneDigitCompactFormatter.format(value)
|
return localeDefinition?.compactNumberPlural ?? NaN
|
||||||
}
|
|
||||||
const twoDigitsCompactFormatter = getCompactFormatter(locale.value, 2)
|
|
||||||
return twoDigitsCompactFormatter.format(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { formatCompactNumber, formatCompactNumberPlural }
|
return { formatCompactNumber, formatCompactNumberPlural }
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export interface LocaleDefinition {
|
|||||||
name: string
|
name: string
|
||||||
translatedName: MessageDescriptor
|
translatedName: MessageDescriptor
|
||||||
numeric?: Intl.RelativeTimeFormatNumeric
|
numeric?: Intl.RelativeTimeFormatNumeric
|
||||||
|
compactNumberPlural?: number
|
||||||
dir?: 'ltr' | 'rtl'
|
dir?: 'ltr' | 'rtl'
|
||||||
serverLanguageCode?: string
|
serverLanguageCode?: string
|
||||||
}
|
}
|
||||||
@@ -92,6 +93,7 @@ export const LOCALES: LocaleDefinition[] = [
|
|||||||
code: 'fil-PH',
|
code: 'fil-PH',
|
||||||
name: 'Filipino',
|
name: 'Filipino',
|
||||||
translatedName: defineMessage({ id: 'locale.fil-PH', defaultMessage: 'Filipino' }),
|
translatedName: defineMessage({ id: 'locale.fil-PH', defaultMessage: 'Filipino' }),
|
||||||
|
compactNumberPlural: 1,
|
||||||
serverLanguageCode: 'tl',
|
serverLanguageCode: 'tl',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user