---
title: "Discussion on \"Typesafe i18n with SvelteKit\" | Hashnode"
description: "Discussion on \"Typesafe i18n with SvelteKit\". How easy it is to create a multi-language site nowadays!"
url: "https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Typesafe i18n with SvelteKit](https://blog.encodeart.dev/typesafe-i18n-with-sveltekit?utm_source=hashnode&utm_medium=feed)

How easy it is to create a multi-language site nowadays!

Jan 9, 2023 · 10 min read · blog.encodeart.dev  
Read the article

-   [#i18n](https://hashnode.com/tag/i18n)
-   [#sveltekit](https://hashnode.com/tag/sveltekit)
-   [#svelte](https://hashnode.com/tag/svelte)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#translation](https://hashnode.com/tag/translation)

## Written by

[Andreas Söderlund](https://hashnode.com/@encodeart)

@encodeart · Sweden

  
[View profile](https://hashnode.com/@encodeart)

Uniting art and engineering in code

Is programming art, engineering or both? This is what I try to figure out, while striving towards user friendliness, simplicity and synergy. Philosophical when writing, precise when coding. DCI (Data, Context, Interaction) has been my major area of research for the last 10 years. Creator of Superforms for SvelteKit.

## Responses 6

Markdown supported · ⌘↵ to post

[David Brutt](https://hashnode.com/@DBrutte)

[Jul 9, 2024](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/668d04ab35ae494fe84a738b)

Hi. Great article. Saved me time. I would like to ask you why you added

await loadLocaleAsync(locale);

setLocale(locale);

In the Hook.server and in Layout.ts

as I checked adding this code at Layout.ts should do the work.

Am I missing here something?

[Tomek Różalski](https://hashnode.com/@muzykolog84)

[May 17, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/64649e29a2c49bc61afe41d1)

Great job! I just have issue with prerender. I try prerender home page and I get:

```
Error: The following routes were marked as prerenderable, but were not prerendered because they were not found while crawling your app:
  - /[[lang=langCode]]
```

Seems like crawler whats to start from root path and there is only +error and +layout files 🤔

[Tomek Różalski](https://hashnode.com/@muzykolog84)

[May 17, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/64649e29a2c49bc61afe41d1#reply-6464f145d72293df32dfb110)

Ah, fixed by adding to svelte.config.js

```
prerender: {
    crawl: true,
    entries: ['/', '/en']
}
```

:)

[David Brutt](https://hashnode.com/@DBrutte)

[Jul 9, 2024](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/64649e29a2c49bc61afe41d1#reply-668d6a0767153945897ee720)

[Tomek Różalski](https://hashnode.com/@muzykolog84)

Hi. Did it work you with adapter-static with prerender?

for me, it is making the folder /de empty.

[Tobias](https://hashnode.com/@Tobfather)

[Mar 26, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/6420526cdf7f026515a61fa4)

Thank you so much for this article! It made it so clear and simple to follow along and saved me so much time. I'd like to ask you if you prefer using the route- or cookie-way of doing it? I think using a cookie would be simpler and easier to maintain but I can't see what are the disadvantages?

[Andreas Söderlund](https://hashnode.com/@encodeart)

[Mar 26, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/6420526cdf7f026515a61fa4#reply-64205a0adf7f026515a620df)

Hi Tobias, I'm glad I could make things easier for you. :) I can't say I have a preference, the method to use depends on the site and its requirements. Cookies makes for cleaner routes, but from a SEO perspective it could be better to use the route way, for example. It's hard to say without knowing more about the specific site you're making.

[Tobias](https://hashnode.com/@Tobfather)

[Mar 26, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/6420526cdf7f026515a61fa4#reply-64207438df7f026515a62626)

[Andreas Söderlund](https://hashnode.com/@encodeart) Ok, thank you for your answer. I don't have any specific requirements for it's a side-project I'm working on but I thought it could have implications for seo but wasn't sure about it. I'll try to find some resources to make a more profound decision.

[Jens](https://hashnode.com/@nussknagger)

[Feb 25, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/63fa59ae4601ef02c201eaaa)

Great article! The only two things that I am missing is the automatic detection of the browser language through the header and a language switcher - could you possibly add this in the future? 🙏

[Andreas Söderlund](https://hashnode.com/@encodeart)

[Mar 6, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/63fa59ae4601ef02c201eaaa#reply-6405e2e585656fc842a49ee0)

Hi Jens, I think I'll leave that as an exercise to the reader, it should be quite easy to modify the cookie example at the end to look at the relevant headers instead of the cookie data.

[Pavel Stianko](https://hashnode.com/@stianko)

[Jan 19, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/63c9209181ec00896796b3ca)

Thanks for the awesome content Andreas! Best article about typesafe-i18n that I found! I am using routing for lang detection, but the content of the page is changing when I hover the links to different lang version (I am using hrefs to /de, /en,..). I know I can disable data preload in sveltekit, but is there any better solution? Thank you!

[Andreas Söderlund](https://hashnode.com/@encodeart)

[Jan 19, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/63c9209181ec00896796b3ca#reply-63c92dfef33a078eb1c8ecde)

Hi Pavel, glad you like the article! :) I see the problem. In this case I'd pass the "LINK" translation string/locale as page data instead, so it's definitely available.

[Ayush Agarwal](https://hashnode.com/@ayushdev24)

[Jan 14, 2023](https://hashnode.com/posts/typesafe-i18n-with-sveltekit/63bc196214626743de083639/comment/63c3005603c1653613d91309)

Very nice explained Andreas, great code snippets to code and learn along.
