You've already forked AstralRinth
forked from didirus/AstralRinth
Add internationalization support (#738)
This commit is contained in:
18
composables/compact-number.ts
Normal file
18
composables/compact-number.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createFormatter, type Formatter } from '@vintl/compact-number'
|
||||
import { IntlController } from '@vintl/vintl/controller'
|
||||
|
||||
const formatters = new WeakMap<IntlController<any>, Formatter>()
|
||||
|
||||
export function useCompactNumber(): Formatter {
|
||||
const vintl = useVIntl()
|
||||
|
||||
let formatter = formatters.get(vintl)
|
||||
|
||||
if (formatter == null) {
|
||||
const formatterRef = computed(() => createFormatter(vintl.intl))
|
||||
formatter = (value, options) => formatterRef.value(value, options)
|
||||
formatters.set(vintl, formatter)
|
||||
}
|
||||
|
||||
return formatter
|
||||
}
|
||||
18
composables/how-ago.ts
Normal file
18
composables/how-ago.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createFormatter, type Formatter } from '@vintl/how-ago'
|
||||
import { IntlController } from '@vintl/vintl/controller'
|
||||
|
||||
const formatters = new WeakMap<IntlController<any>, Formatter>()
|
||||
|
||||
export function useRelativeTime(): Formatter {
|
||||
const vintl = useVIntl()
|
||||
|
||||
let formatter = formatters.get(vintl)
|
||||
|
||||
if (formatter == null) {
|
||||
const formatterRef = computed(() => createFormatter(vintl.intl))
|
||||
formatter = (value, options) => formatterRef.value(value, options)
|
||||
formatters.set(vintl, formatter)
|
||||
}
|
||||
|
||||
return formatter
|
||||
}
|
||||
Reference in New Issue
Block a user