mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-06-30 18:54:49 +02:00
refactor: 💡 formatter format/manual options logic
This commit is contained in:
parent
850fd09f32
commit
9d636694b1
|
@ -42,12 +42,9 @@ export const getDateFormatter: MemoizedIntlFormatter<
|
||||||
throw new Error('[svelte-i18n] A "locale" must be set to format dates')
|
throw new Error('[svelte-i18n] A "locale" must be set to format dates')
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasInlineArgs = Object.keys(options).length > 0
|
if (format) options = getIntlFormatterOptions('date', format)
|
||||||
if (!hasInlineArgs) {
|
else if (Object.keys(options).length === 0) {
|
||||||
options =
|
options = getIntlFormatterOptions('date', 'short')
|
||||||
typeof format === 'string'
|
|
||||||
? getIntlFormatterOptions('date', format)
|
|
||||||
: getIntlFormatterOptions('date', 'short')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Intl.DateTimeFormat(locale, options)
|
return new Intl.DateTimeFormat(locale, options)
|
||||||
|
@ -64,12 +61,9 @@ export const getTimeFormatter: MemoizedIntlFormatter<
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasInlineArgs = Object.keys(options).length > 0
|
if (format) options = getIntlFormatterOptions('time', format)
|
||||||
if (!hasInlineArgs) {
|
else if (Object.keys(options).length === 0) {
|
||||||
options =
|
options = getIntlFormatterOptions('time', 'short')
|
||||||
typeof format === 'string'
|
|
||||||
? getIntlFormatterOptions('time', format)
|
|
||||||
: getIntlFormatterOptions('time', 'short')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Intl.DateTimeFormat(locale, options)
|
return new Intl.DateTimeFormat(locale, options)
|
||||||
|
|
|
@ -5,7 +5,7 @@ export function defineMessages(i: Record<string, MessageObject>) {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
export { configure } from './configs'
|
export { init } from './configs'
|
||||||
export { $locale as locale } from './stores/locale'
|
export { $locale as locale } from './stores/locale'
|
||||||
export {
|
export {
|
||||||
$dictionary as dictionary,
|
$dictionary as dictionary,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
import { lookupMessage } from '../../../src/client/includes/lookup'
|
import { lookupMessage } from '../../../src/client/includes/lookup'
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isFallbackLocaleOf,
|
isFallbackLocaleOf,
|
||||||
getFallbackOf,
|
getFallbackOf,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user