Use numeric: always for Italian and Russian (#5293)

* Use `numeric: always` for Italian and Russian

* Use RelativeTimeFormatNumeric type
This commit is contained in:
Jerozgen
2026-02-04 16:49:21 +03:00
committed by GitHub
parent 5d6593a9da
commit 34cbc7e0c1
2 changed files with 11 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { computed, type ComputedRef } from 'vue'
import { injectI18n } from '../providers/i18n'
import { LOCALES } from './i18n.ts'
export type Formatter = (value: Date | number | null | undefined, options?: FormatOptions) => string
@@ -13,13 +14,13 @@ const formatters = new Map<string, ComputedRef<Intl.RelativeTimeFormat>>()
export function useRelativeTime(): Formatter {
const { locale } = injectI18n()
const formatterRef = computed(
() =>
new Intl.RelativeTimeFormat(locale.value, {
numeric: 'auto',
style: 'long',
}),
)
const formatterRef = computed(() => {
const localeDefinition = LOCALES.find((loc) => loc.code === locale.value)
return new Intl.RelativeTimeFormat(locale.value, {
numeric: localeDefinition?.numeric || 'auto',
style: 'long',
})
})
if (!formatters.has(locale.value)) {
formatters.set(locale.value, formatterRef)

View File

@@ -27,6 +27,7 @@ export function defineMessages<K extends string, T extends MessageDescriptorMap<
export interface LocaleDefinition {
code: string
name: string
numeric?: Intl.RelativeTimeFormatNumeric
dir?: 'ltr' | 'rtl'
iso?: string
file?: string
@@ -64,7 +65,7 @@ export const LOCALES: LocaleDefinition[] = [
// { code: 'hu-HU', name: 'Magyar' },
// { code: 'id-ID', name: 'Bahasa Indonesia' },
// { code: 'is-IS', name: 'Íslenska' },
{ code: 'it-IT', name: 'Italiano' },
{ code: 'it-IT', name: 'Italiano', numeric: 'always' },
// { code: 'ja-JP', name: '日本語' },
// { code: 'kk-KZ', name: 'Қазақша' },
// { code: 'ko-KR', name: '한국어' },
@@ -80,7 +81,7 @@ export const LOCALES: LocaleDefinition[] = [
{ code: 'pt-BR', name: 'Português (Brasil)' },
{ code: 'pt-PT', name: 'Português (Portugal)' },
// { code: 'ro-RO', name: 'Română' },
{ code: 'ru-RU', name: 'Русский' },
{ code: 'ru-RU', name: 'Русский', numeric: 'always' },
// { code: 'sk-SK', name: 'Slovenčina' },
// { code: 'sl-SI', name: 'Slovenščina' },
// { code: 'sr-CS', name: 'Српски (ћирилица)' },