Add internationalization support (#738)

This commit is contained in:
Sasha Sorokin
2023-06-11 19:08:16 +01:00
committed by GitHub
parent 776c16cd49
commit de991041c4
12 changed files with 651 additions and 10 deletions

View 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
View 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
}