39 likes
路
7.6K reads
12 comments
Very nice explained Andreas, great code snippets to code and learn along.
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!
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.
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?
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.
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.
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? 馃檹
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.
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 馃
Ah, fixed by adding to svelte.config.js
prerender: {
crawl: true,
entries: ['/', '/en']
}
:)
Hi. Did it work you with adapter-static with prerender?
for me, it is making the folder /de empty.
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?