Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paraglide:lang cookie ignored when reloading url with no lang in it #183

Closed
SaintPepsi opened this issue Aug 7, 2024 · 5 comments
Closed

Comments

@SaintPepsi
Copy link

Hi!

I just implemented the language switcher in our application and I can see the cooking for paraglide:lang getting set.

When remove all paths from the url to refresh back to the index page, the paraglide:lang gets set back to our default language.

Am I missing something here?

We also build the application for Capacitor, which is known not to do that great with cookies.
Do I need to create a custom preference handling system to make sure the user gets served the correct page?

Copy link
Collaborator

Have you configured prefixDefaultLanguage: "always"?
The cookie is only used if the language is ambiguous. By default the default-language lives on / so that's considered unambigous. Only if you configure it so that the default language is also located on /lang will the cookie be used

@SaintPepsi
Copy link
Author

Awesome, it looks like prefixDefaultLanguage: "always" does what we want!
I should have probably tried that before posting an issue.

We're using adaptor static to generate the site for our application. But since adding that key we're getting the error Could not create a fallback page - failed with status 302 which i'm guessing is related to the initial redirect that happens to the correct language path?

Have you had this before?

@LorisSigrist
Copy link
Collaborator

Yeah, you'll probably need to edit the entries for prerendering in svelte.config.js. Just point it to /en.
https://kit.svelte.dev/docs/configuration#prerender

@SaintPepsi
Copy link
Author

Hey @LorisSigrist I tried that, but that didn't seem to do anything.
I didn't realise that the error is actually coming from wrangler:

process.env.VITE_ADAPTER capacitor

/Users/hogers/Documents/repos/EATView 2/node_modules/wrangler/wrangler-dist/cli.js:29747
            throw a;
            ^
Error: Could not create a fallback page — failed with status 302
    at generate_fallback (file:///Users/hogers/Documents/repos/EATView%202/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js:53:8)
    at async MessagePort.<anonymous> (file:///Users/hogers/Documents/repos/EATView%202/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)

Node.js v21.7.2
import adapterAuto from '@sveltejs/adapter-auto';
import cloudflareWorkersAdapter from '@sveltejs/adapter-cloudflare-workers';
import staticAdapter from '@sveltejs/adapter-static';

function getAdapter() {
	console.log('process.env.VITE_ADAPTER', process.env.VITE_ADAPTER);
	switch (process.env.VITE_ADAPTER) {
		case 'capacitor':
			return staticAdapter({
				strict: false,
				pages: 'build/capacitor',
				assets: 'build/capacitor',
				fallback: 'index.html',
			});

		case 'cloudflare-workers':
			return cloudflareWorkersAdapter();

		default:
			return adapterAuto();
	}
}

Do you have any suggestions on how I can debug this?

@SaintPepsi
Copy link
Author

I was able to resolve this redirect warning with here: sveltejs/kit#9386 (comment)

by not adding the i18n.handle to the list of Handles when building

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants