opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
52 stars 1 forks source link

Can I switch langs without the use of the url? #134

Closed Antoine-lb closed 5 months ago

Antoine-lb commented 5 months ago

Hello 👋

This lib is amazing, great work!

I was wandering if I can change a language without changing the URL, by keeping in the a Svelte Store or in local storage for example.

So example.com can be in spanish or english depending on the user device language (all done in JS).

Thanks!

LorisSigrist commented 5 months ago

Currently no

We went with prefix-based routing because it works in all environments SvelteKit could possibly output to, including static sites.

However, expanding the routing options that are available is something we want to do, so this will likely be possible in the future

Antoine-lb commented 5 months ago

Nice. Maybe a middel ground could be a query param, which in my case would work perfectly. So:

example.com/about -> English
example.com/about?lang=fr -> French

If I'm not mistaken this could also work in all environments

samuelstroschein commented 5 months ago

why would you want that? best practice is /{locale}/page

Antoine-lb commented 5 months ago

I have multiple apps in the same domain:

example.com/app1
example.com/app2
example.com/app3

The right solution would have been to create a sub-domain for each, but we didn't, and now it's a bit too late 😅

The root of the issue is that security is done based on that initial path /app1. Adding langs would mess this up.

I could keep digging to make it work, but honestly I kind off like it on JS.

Why is it best practice?

LorisSigrist commented 5 months ago

If they're Sveltekit Apps you can change the base path of your SvelteKit project in svelte.config.js. This will move the language param after the base path.

Having it after is only not possible within the same sveltekit project.

samuelstroschein commented 5 months ago

i see. wouldn't this suffice then

example.com/app1/locale/path
example.com/app2/locale/path

Why is it best practice?

Most apps use this pattern leading to "the most common way" for users to know on which site they are. Compare both urls:

example.com/{locale}/path-saoin3-asi8h2-as2nasgh2-2s8h29j29h29hs=sss
example.com/path-saoin3-asi8h2-as2nasgh2-2s8h29j29h29hs=sss?l={locale}
Antoine-lb commented 5 months ago

So here is my exact problem, we are an app that builds QR menus for restaurants, and the QR menus are already printed.

toto.menu/baco/menu -> A menu that is by default in Spanish
toto.menu/the-hideout/menu -> A menu that is by default in French
toto.menu/boteco/menu -> A menu that is by default in Portugues

May problem is that the defualt language is not the same depending on the route.

If they're Sveltekit Apps you can change the base path of your SvelteKit project in svelte.config.js. This will move the language param after the base path

It's all just ONE SvelteKit app, so changing the base will not work form me

LorisSigrist commented 5 months ago

I see. Unfortunately that's not something that can be done right now, it would need an overhaul to the routing system. We will eventually introduce something akin to the Routing strategies in Paraglide-NextJS for Paraglide-SvelteKit, but that's not here yet.

In the meantime you might be able to get it to work using something like sveltekit-redirections to redirect the QR-Code urls to the App-URLs.

Antoine-lb commented 5 months ago

I see. Unfortunately that's not something that can be done right now, it would need an overhaul to the routing system. We will eventually introduce something akin to the Routing strategies in Paraglide-NextJS for Paraglide-SvelteKit, but that's not here yet.

In the meantime you might be able to get it to work using something like sveltekit-redirections to redirect the QR-Code urls to the App-URLs.

Thanks! I will try to make it work the way you have set-up right now