Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-onions-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix(paraglide): git ignore cache of inlang project
5 changes: 5 additions & 0 deletions .changeset/thick-vans-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix(paraglide): multi language when prerendering is now working by default
54 changes: 36 additions & 18 deletions packages/sv/lib/addons/paraglide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,6 @@ export default defineAddon({

sv.devDependency('@inlang/paraglide-js', '^2.6.0');

sv.file('project.inlang/settings.json', (content) => {
if (content) return content;

const { data, generateCode } = parseJson(content);

for (const key in DEFAULT_INLANG_PROJECT) {
data[key] = DEFAULT_INLANG_PROJECT[key as keyof typeof DEFAULT_INLANG_PROJECT];
}
const { validLanguageTags } = parseLanguageTagInput(options.languageTags);
const baseLocale = validLanguageTags[0];

data.baseLocale = baseLocale;
data.locales = validLanguageTags;

return generateCode();
});

// add the vite plugin
sv.file(files.viteConfig, (content) => {
const { ast, generateCode } = parseScript(content);
Expand Down Expand Up @@ -178,11 +161,46 @@ export default defineAddon({
if (!content) return content;

if (!content.includes(`\n${paraglideOutDir}`)) {
content = content.trimEnd() + `\n\n# Paraglide\n${paraglideOutDir}`;
content = content.trimEnd() + `\n\n# Paraglide\n${paraglideOutDir}\nproject.inlang/cache/`;
}
return content;
});

sv.file('project.inlang/settings.json', (content) => {
if (content) return content;

const { data, generateCode } = parseJson(content);

for (const key in DEFAULT_INLANG_PROJECT) {
data[key] = DEFAULT_INLANG_PROJECT[key as keyof typeof DEFAULT_INLANG_PROJECT];
}
const { validLanguageTags } = parseLanguageTagInput(options.languageTags);
const baseLocale = validLanguageTags[0];

data.baseLocale = baseLocale;
data.locales = validLanguageTags;

return generateCode();
});

sv.file(`${kit.routesDirectory}/+layout.svelte`, (content) => {
const { ast, generateCode } = parseSvelte(content);
const scriptAst = svelte.ensureScript(ast);
imports.addNamed(scriptAst, {
imports: ['locales', 'localizeHref'],
from: '$lib/paraglide/runtime'
});
imports.addNamed(scriptAst, { imports: ['page'], from: '$app/state' });
ast.fragment.nodes.push(
...svelte.toFragment(`<div style="display:none">
{#each locales as locale}
<a href={localizeHref(page.url.pathname, { locale })}>{locale}</a>
{/each}
</div>`)
);
return generateCode();
});

if (options.demo) {
sv.file(`${kit.routesDirectory}/demo/+page.svelte`, (content) => {
return addToDemoPage(content, 'paraglide', typescript);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ vite.config.ts.timestamp-*

# Paraglide
src/lib/paraglide
project.inlang/cache/

# SQLite
*.db
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<script lang="ts">
import { page } from '$app/state';
import { locales, localizeHref } from '$lib/paraglide/runtime';
import './layout.css';
import favicon from '$lib/assets/favicon.svg';

let { children } = $props();
</script>

<svelte:head><link rel="icon" href={favicon} /></svelte:head>

{@render children()}
<div style="display:none">
{#each locales as locale}
<a
href={localizeHref(page.url.pathname, { locale })}
>
{locale}
</a>
{/each}
</div>
Loading