Use numeric: always for Italian and Russian (#5293)
* Use `numeric: always` for Italian and Russian * Use RelativeTimeFormatNumeric type
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { computed, type ComputedRef } from 'vue'
|
import { computed, type ComputedRef } from 'vue'
|
||||||
|
|
||||||
import { injectI18n } from '../providers/i18n'
|
import { injectI18n } from '../providers/i18n'
|
||||||
|
import { LOCALES } from './i18n.ts'
|
||||||
|
|
||||||
export type Formatter = (value: Date | number | null | undefined, options?: FormatOptions) => string
|
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 {
|
export function useRelativeTime(): Formatter {
|
||||||
const { locale } = injectI18n()
|
const { locale } = injectI18n()
|
||||||
|
|
||||||
const formatterRef = computed(
|
const formatterRef = computed(() => {
|
||||||
() =>
|
const localeDefinition = LOCALES.find((loc) => loc.code === locale.value)
|
||||||
new Intl.RelativeTimeFormat(locale.value, {
|
return new Intl.RelativeTimeFormat(locale.value, {
|
||||||
numeric: 'auto',
|
numeric: localeDefinition?.numeric || 'auto',
|
||||||
style: 'long',
|
style: 'long',
|
||||||
}),
|
})
|
||||||
)
|
})
|
||||||
|
|
||||||
if (!formatters.has(locale.value)) {
|
if (!formatters.has(locale.value)) {
|
||||||
formatters.set(locale.value, formatterRef)
|
formatters.set(locale.value, formatterRef)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export function defineMessages<K extends string, T extends MessageDescriptorMap<
|
|||||||
export interface LocaleDefinition {
|
export interface LocaleDefinition {
|
||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
|
numeric?: Intl.RelativeTimeFormatNumeric
|
||||||
dir?: 'ltr' | 'rtl'
|
dir?: 'ltr' | 'rtl'
|
||||||
iso?: string
|
iso?: string
|
||||||
file?: string
|
file?: string
|
||||||
@@ -64,7 +65,7 @@ export const LOCALES: LocaleDefinition[] = [
|
|||||||
// { code: 'hu-HU', name: 'Magyar' },
|
// { code: 'hu-HU', name: 'Magyar' },
|
||||||
// { code: 'id-ID', name: 'Bahasa Indonesia' },
|
// { code: 'id-ID', name: 'Bahasa Indonesia' },
|
||||||
// { code: 'is-IS', name: 'Íslenska' },
|
// { code: 'is-IS', name: 'Íslenska' },
|
||||||
{ code: 'it-IT', name: 'Italiano' },
|
{ code: 'it-IT', name: 'Italiano', numeric: 'always' },
|
||||||
// { code: 'ja-JP', name: '日本語' },
|
// { code: 'ja-JP', name: '日本語' },
|
||||||
// { code: 'kk-KZ', name: 'Қазақша' },
|
// { code: 'kk-KZ', name: 'Қазақша' },
|
||||||
// { code: 'ko-KR', name: '한국어' },
|
// { code: 'ko-KR', name: '한국어' },
|
||||||
@@ -80,7 +81,7 @@ export const LOCALES: LocaleDefinition[] = [
|
|||||||
{ code: 'pt-BR', name: 'Português (Brasil)' },
|
{ code: 'pt-BR', name: 'Português (Brasil)' },
|
||||||
{ code: 'pt-PT', name: 'Português (Portugal)' },
|
{ code: 'pt-PT', name: 'Português (Portugal)' },
|
||||||
// { code: 'ro-RO', name: 'Română' },
|
// { code: 'ro-RO', name: 'Română' },
|
||||||
{ code: 'ru-RU', name: 'Русский' },
|
{ code: 'ru-RU', name: 'Русский', numeric: 'always' },
|
||||||
// { code: 'sk-SK', name: 'Slovenčina' },
|
// { code: 'sk-SK', name: 'Slovenčina' },
|
||||||
// { code: 'sl-SI', name: 'Slovenščina' },
|
// { code: 'sl-SI', name: 'Slovenščina' },
|
||||||
// { code: 'sr-CS', name: 'Српски (ћирилица)' },
|
// { code: 'sr-CS', name: 'Српски (ћирилица)' },
|
||||||
|
|||||||
Reference in New Issue
Block a user