sveltekit-i18n / lib

Internationalization library built for SvelteKit.
MIT License
447 stars 28 forks source link

Can't load translations correctly from .ts file #168

Open FranciscoHS19 opened 5 months ago

FranciscoHS19 commented 5 months ago

Hello all,

First, let me thank you for this amazing package :)

I have a .ts file in which I'm storing default system messages:

export const systemMessages = {
    // Success messages
    createSuccess: t.get('staticMessages.createSuccess'),
    updateSuccess: t.get('staticMessages.updateSuccess'),
}

I'm able to use correct translations when making API calls that then use systemMessages and return it to the front-end. However, when using them directly in a .svelte file and trying to trigger them on an onMount, the message is empty and I get warnings on my browser message saying: "No locale provided for 'staticMessages.createSuccess' key. Skipping translation..." for every single message

onMount(() => {
        const createSuccess = $page.url.searchParams.get('createSuccess');
        if (createSuccess) {
            toastStore.trigger(systemMessages.createSuccess);
        }
    });