kaisermann / svelte-i18n

Internationalization library for Svelte

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting the timezone in the init method

Tiim opened this issue · comments

commented

Is your feature request related to a problem? Please describe.
I'm using SvelteKit with SSR rendering turned on and the server has a different time zone than the users. This causes formatted times to flicker with the wrong time when loading the page unless the time zone is manually specified as mentioned in issue #148.

Describe the solution you'd like
I would like to be able to set the time zone in the init method. This would still be overridden when specified in the $time method.

// this function can be called on the client side without arguments
// and on the server side with 
// - the locale from the accept-language http header 
// - the time zone from a client side set cookie
export async function initLocalisation(locale, timeZone) {
	register('en', () => import('../locales/en.json'));
	register('de', () => import('../locales/de.json'));

	if (!locale) {
		locale = getLocaleFromNavigator();
	}

	await init({
		fallbackLocale: 'en',
		initialLocale: locale,
		timeZone,
	});
}

Describe alternatives you've considered
Currently all calls to $time and $date must pass the {timeZone: ...} option.

How important is this feature to you?
I think this would be a nice convenience feature, especially since SvelteKit and SSR rendering is getting more popular.

Additional context