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

Redirect to location if not location is set #1

Closed
BetaConnector opened this issue Dec 5, 2020 · 8 comments
Closed

Redirect to location if not location is set #1

BetaConnector opened this issue Dec 5, 2020 · 8 comments

Comments

@BetaConnector
Copy link

Hey,

I am waiting for the plugin and I was wondering about redirects.
For example if a user navigates to my site https://www.mysite.com it should redirect to https://www.mysite.com/en and the language should be taken by path (svelte-i18n: getLocaleFromPathname).

Is there solution in this plugin or should I think of a own implementation?

Thanks in advanced - Alex

@kiuKisas
Copy link
Owner

kiuKisas commented Dec 5, 2020

Sorry for the wait, I'm busy with other things these days.

The svelte-i18n implementation will define locales and dictionary for you, and let you set init options. You will be able to set the initialLocale to getLocaleFromNavigator() so it will work as you expect as a feature of svelte-i18n.

It will probably be done next week btw :)

@BetaConnector
Copy link
Author

Cool - looking forward for the plugin.
Thanks for your work!

@kiuKisas
Copy link
Owner

Hey, I've been late on this feature.
More test are needed but you can check my current progress on this, with an non exhaustive to-do: #3

@esyon
Copy link

esyon commented Dec 31, 2020

@kiuKisas, i checked the progress and I am glad to see that you are still working on it.

Thanks for your effort!

@kiuKisas
Copy link
Owner

kiuKisas commented Jan 3, 2021

Hey @BetaConnector , about your initial question, regarding redirection...
I get confuse with svelte-i18nand give you a wrong answer.. because it doesn't provide redirection, it change the content according to the current locale. (that make sense since it's target "vanilla svelte").

I apologized for that.

I'm starting to doubt the use of an integration with svelte-i18n as it requires hydration (complete if we want to internationalize the whole site), which is the opposite of what elderjs proposes. Moreover, it doesn't seem to bring much in the end...

But so be it, I'm going to finish what I've started. Let's just say that it makes an easier transition from any svelte project with svelte-i18n to elderjs :) (or a svelte component dependent of svelte-i18n).

All is not lost, it allows me to explore ways to add client code from an elderjs plugin and also to integrate in this project a "generic" base for client-side integration.

Now, after svelte-i18n integration, the plan is to take care of a redirection feature without rehydratation (as it's not needed).

You can technically already do that as I expose the different permalinks of each locale with getAllPermalinks. All you have to do is to implement a way to get the current locale (propably with navigator) and redirect according to it. If you can wait, an helper will be available later (as I explain earlier).
NOTE: if your urls are the same for each locales except a lang prefix (e.g: /en/about and /fr/about), you don't even need getAllPermalinks result, so it can be straightforward. In this case, I can write a tiny gist if you want to.

N.B: With your initial comment in mind, the language will not be taken from path, as the path is already made from language. We don't have to care about it :).

Also, note that google don't recommend to use redirection as I mention in #4

I keep this issue close in favor of #4

@BetaConnector
Copy link
Author

Hey @kiuKisas, thanks for your explanation.

My plan is to use language specific urls (/en/about and /de/ueber-uns).

I think right now I will wait fo you to finish the helper.

Also, note that google don't recommend to use redirection as I mention in #4

I think the main concern of google is that the user or crawler won't be able to find the other language:

Avoid automatic redirection based on the user's perceived language. These redirections could prevent users (and search engines) from viewing all the versions of your site.

So if every english page has a link to the german version i think the initial redirect should be not a big deal.

Initial redirect means the redirect if no language is set:
www.domain.net -> www.domain.net/en

As far as I understood I have to take care of this redirect, since this plugin won't take care of it?

Thanks for your effort!

@kiuKisas
Copy link
Owner

kiuKisas commented Jan 4, 2021

ok, so if I understand, www.domain.net doesn't have any content, but you have www.domain.net/en and www.domain.net/de right ? So you need a redirection on your home www.domain.net only, correct ?

You probably should manage that from your server as it's a one time redirection, for example, if you have a nginx server, you can follow this: https://stackoverflow.com/questions/3657614/how-to-rewrite-location-in-nginx-depending-on-the-client-browsers-language

NOTE: in elder-plugin-i18n, you should set prefixDefault to true for this case.

@BetaConnector
Copy link
Author

@kiuKisas, exactly that's what I am trying to achieve.

As I am planing to host on netlify I am not quite sure about the redirects - that's why i thought redirecting via JS.

But there seems to be a better way (server side):
https://docs.netlify.com/routing/redirects/#syntax-for-the-netlify-configuration-file
https://docs.netlify.com/routing/redirects/redirect-options/#http-status-codes
https://docs.netlify.com/routing/redirects/rewrites-proxies/#signed-proxy-redirects

Thanks for the hint! 👍

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

3 participants