Skip to content

Sapper minimal working example? #304

@jesperp

Description

@jesperp

Version

5.4.2

Describe the bug

I'm trying to get a minimal working example in Sapper (can't use Sveltekit yet..) and the SSR output works but client then renders an empty translation. There was actually a similar bug for me when I tried to make sveltekit-i18n work with sapper (quick flash of SSR content before displaying empty translation).

Any ideas? :)

Reproduction

Start a new sapper project and install/setup typesafe-i18n

pnpx degit "sveltejs/sapper-template#rollup" typesafe-i18n-sapper
cd  typesafe-i18n-sapper
node scripts/setupTypeScript.js
pnpm i typesafe-i18n
./node_modules/typesafe-i18n/cli/typesafe-i18n.mjs --setup-auto
pnpm typesafe-i18n

Now edit the _layout.svelte file's script tags:

<script lang="ts" context="module">
   import { loadLocaleAsync } from '../i18n/i18n-util.async'

   export async function preload(page, session) {
      const locale = 'en'
      await loadLocaleAsync(locale)

      // NOTE: Comment out this `return` and it works... hmm
      return { props: { locale } }
   }
</script>

<script lang="ts">
  import Nav from '../components/Nav.svelte';
  import { setLocale } from '../i18n/i18n-svelte'

  export let segment: string;
  export let locale: string;

  setLocale(locale || 'en')

  $: console.log("HI:",  $LL.HI({ name: "You" }) )
</script>

The server logs HI: Hi You! and the client logs HI:

Logs

No response

Config

{
   "adapter": "svelte",
   "$schema": "https://unpkg.com/typesafe-i18n@5.4.2/schema/typesafe-i18n.json"
}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions