forked from cms/tibi-svelte-starter
✨ feat: enhance SSR support with language extraction, dynamic page titles, and updated styles; adjust color theme
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { addMessages, init } from "svelte-i18n"
|
||||
import { DEFAULT_LANGUAGE } from "./lib/i18n"
|
||||
import { render } from "svelte/server"
|
||||
import { addMessages, init, locale } from "svelte-i18n"
|
||||
import { DEFAULT_LANGUAGE, extractLanguageFromPath } from "./lib/i18n"
|
||||
import deLocale from "./lib/i18n/locales/de.json"
|
||||
import enLocale from "./lib/i18n/locales/en.json"
|
||||
import App from "./App.svelte"
|
||||
@@ -8,9 +9,30 @@ import App from "./App.svelte"
|
||||
addMessages("de", deLocale)
|
||||
addMessages("en", enLocale)
|
||||
|
||||
init({
|
||||
fallbackLocale: DEFAULT_LANGUAGE,
|
||||
initialLocale: DEFAULT_LANGUAGE,
|
||||
})
|
||||
/**
|
||||
* SSR render wrapper for Svelte 5.
|
||||
*
|
||||
* tibi-server calls `app.default.render({ url })`.
|
||||
* Svelte 5 no longer provides a `.render()` method on components —
|
||||
* instead `render()` must be imported from `svelte/server`.
|
||||
*
|
||||
* This wrapper keeps the hook-side API compatible while delegating
|
||||
* to the Svelte 5 render function internally.
|
||||
*/
|
||||
export default {
|
||||
render({ url }: { url: string }) {
|
||||
const lang = extractLanguageFromPath(url) || DEFAULT_LANGUAGE
|
||||
|
||||
export default App
|
||||
init({
|
||||
fallbackLocale: DEFAULT_LANGUAGE,
|
||||
initialLocale: lang,
|
||||
})
|
||||
locale.set(lang)
|
||||
|
||||
const { body, head } = render(App, {
|
||||
props: { url },
|
||||
})
|
||||
|
||||
return { html: body, head }
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user