Localized Date, Datetime, Time, and Number #62
-
I'm currently evaluating this lib as a i18n - solution and I have quit offen the case, that I want to localize a date or a number. I'm currently solving this with an additional store, like this one: export const datetime = derived(locale, ($locale) => (date, option: Intl.DateTimeFormatOptions = {}) => {
if (!(date instanceof Date)) {
date = new Date(date);
}
return new Intl.DateTimeFormat($locale, option).format(date);
}); and call it in Svelte: <span>{$datetime(createdAt)}</span> Are you likly to add these functionality? If yes, I could also provide one (or multiple) Pull Requests. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @kulturbande! This functionality is already included in @sveltekit-i18n/parser-default. As you can see in the parser-default example you can use modifiers (defined here and used here) to get what you need.) If build-in modifiers do not fit your needs, you can even create your own!:) You can use either Hope it will help.) PS: If you'd rather use ICU message syntax take a look at |
Beta Was this translation helpful? Give feedback.
Hi @kulturbande!
This functionality is already included in @sveltekit-i18n/parser-default.
As you can see in the parser-default example you can use modifiers (defined here and used here) to get what you need.) If build-in modifiers do not fit your needs, you can even create your own!:)
You can use either
@sveltekit-i18n/base
together with@sveltekit-i18n/parser-default
(as presented in the example) or simplysveltekit-i18n
which basically glues these two packages together.Hope it will help.)
PS: If you'd rather use ICU message syntax take a look at
@sveltekit-i18n/parser-icu
– example here – it providesnumber
anddate
formatters as well.