Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/ui/src/composables/how-ago.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/composables/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: '한국어' },
Expand All @@ -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: 'Српски (ћирилица)' },
Expand Down