fix: translation
This commit is contained in:
7
src/routes/+layout.server.ts
Normal file
7
src/routes/+layout.server.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { languageService } from '$lib/server/LanguageService'
|
||||
import type { LayoutServerLoad } from './$types'
|
||||
|
||||
export const load: LayoutServerLoad = async () => {
|
||||
const translations = await languageService.getTranslations(['de'])
|
||||
return translations
|
||||
}
|
||||
@@ -6,8 +6,25 @@
|
||||
Tolgee,
|
||||
DevTools,
|
||||
FormatSimple,
|
||||
type TolgeeStaticData,
|
||||
} from '@tolgee/svelte'
|
||||
import { TopBar } from '$lib/components/ui/topBar'
|
||||
import {
|
||||
PUBLIC_TOLGEE_API_KEY,
|
||||
PUBLIC_TOLGEE_API_URL,
|
||||
} from '$env/static/public'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
let { children, data }: { data: TolgeeStaticData; children: Snippet } =
|
||||
$props()
|
||||
|
||||
function getLang(lang: string) {
|
||||
return async (): Promise<Record<string, any>> => {
|
||||
const res = await fetch(`/lang/${lang}`)
|
||||
const translations = await res.json()
|
||||
return translations
|
||||
}
|
||||
}
|
||||
|
||||
const tolgee = Tolgee()
|
||||
.use(DevTools())
|
||||
@@ -15,15 +32,15 @@
|
||||
.init({
|
||||
language: 'de',
|
||||
|
||||
// for development
|
||||
apiUrl: import.meta.env.VITE_TOLGEE_API_URL,
|
||||
apiKey: import.meta.env.VITE_TOLGEE_API_KEY,
|
||||
// // for development
|
||||
// apiUrl: PUBLIC_TOLGEE_API_URL,
|
||||
// apiKey: PUBLIC_TOLGEE_API_KEY,
|
||||
|
||||
// for production
|
||||
staticData: {},
|
||||
staticData: {
|
||||
de: data['de'] ?? getLang('de'),
|
||||
},
|
||||
})
|
||||
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
10
src/routes/lang/[language]/+server.ts
Normal file
10
src/routes/lang/[language]/+server.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { json } from '@sveltejs/kit'
|
||||
import { languageService } from '$lib/server/LanguageService.js'
|
||||
|
||||
export async function GET({ params }) {
|
||||
const { language } = params
|
||||
|
||||
const result = await languageService.getTranslations([language])
|
||||
|
||||
return json(result[language])
|
||||
}
|
||||
Reference in New Issue
Block a user