Sign in
Log inSign up
Andreas S枚derlund

39 likes

7.6K reads

12 comments

Ayush Agarwal
Ayush Agarwal
Jan 14, 2023

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

1
Pavel Stianko
Pavel Stianko
Jan 19, 2023

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!

1
1 reply
Andreas S枚derlund
Andreas S枚derlund
Author
Jan 19, 2023

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.

Tobias
Tobias
Mar 26, 2023

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?

1
2 replies
Andreas S枚derlund
Andreas S枚derlund
Author
Mar 26, 2023

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.

1
Tobias
Tobias
Mar 26, 2023

Andreas S枚derlund 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
Jens
Feb 25, 2023

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? 馃檹

1 reply
Andreas S枚derlund
Andreas S枚derlund
Author
Mar 6, 2023

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.

Tomek R贸偶alski
Tomek R贸偶alski
May 17, 2023

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 馃

2 replies
Tomek R贸偶alski
Tomek R贸偶alski
May 17, 2023

Ah, fixed by adding to svelte.config.js

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

:)

David Brutt
David Brutt
Jul 9, 2024

Tomek R贸偶alski

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

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

David Brutt
David Brutt
Jul 9, 2024

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?