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

Suggestion - automatic language switching #37

Open
hovi opened this issue Oct 10, 2016 · 6 comments
Open

Suggestion - automatic language switching #37

hovi opened this issue Oct 10, 2016 · 6 comments

Comments

@hovi
Copy link

hovi commented Oct 10, 2016

Re using SOLID_I18N_USE_REDIRECTS and set_language redirect view.

Correct me if I am wrong, but set_language redirect view is used to switch language for cases when language is not part of url for example, because if so, changing to language-aware itself should be act of switching language. I see no reason using that view for unnecessary redirect since I have language-aware urls.

Anyway I was playing around with it and changed middleware to logic that it doesn't try to use redirects if it already finds LANGUAGE_SESSION_KEY in session + it also sets this variable at end of process_request.

Can make pull request, with complete example, but just checking if it makes sense.

Cheers, thanks for the code, been using it for months on production without SOLID_I18N_USE_REDIRECTS.

@pierreben
Copy link

Hi,

I totally agree with this behavior.
I've also made a little change to the middleware in order to redirect the users on the first request if they haven't a language set in cookie or session.
If you're interested in such feature, please have a look at this commit: pierreben@bba183a.
If you wish, I can add an option in settings and write the missing tests.

@hovi
Copy link
Author

hovi commented Jan 7, 2017

Hi,

since django 1.10 now supports same language switching as solid-i18n. I like what you did, I'd suggest posting it as django issue or creating separate iddleware just for this functionality.

@st4lk
Copy link
Owner

st4lk commented Jan 7, 2017

@hovi @pierreben
Guys, thanks for the suggestion and sorry for late response.
I understand your idea, but I'm not sure that it is a good way. If I understand correctly, with such behavior we can have different content on the same url depending on some key in session.
I prefer to avoid it because some search engines can not work well with it.

@pierreben
Copy link

Hi guys,
Thanks for your feedback.
It's a good news that this functionality is included in 1.10.
We're waiting for the 1.11 LTS before upgrading so we will still use django-solid-i18n-urls for a while.

Actually, what I suggest doesn't serve a different content for the same URL, but it creates a 302 redirect to the language that best suits the user browser configuration.
I think that regarding the crawlers, it's quite the same as the SOLID_I18N_USE_REDIRECTS option.
The problem is that it will help the user only on his first visit. For this reason it's certainly not a good solution.
Moreover, your feedback made me think about what would happened if the crawler doesn't support the cookies. In this case it is certainly possible that it can never crawl the pages of the default language because it will always encounter a 302 redirect on /.
But, I think that this drawback also occurs when the SOLID_I18N_USE_REDIRECTS is activated because the only way to switch to the default language is to use the set_language view if the crawler has a HTTP_ACCEPT_LANGUAGE that differs from DEFAULT_LANGUAGE.

To solve this issue, what do you think about configuring SOLID_I18N_USE_REDIRECTS to False and to use a redirect in Javascript ?

@st4lk
Copy link
Owner

st4lk commented Jan 10, 2017

Maybe I not understand the idea fully.
@hovi

Correct me if I am wrong, but set_language redirect view is used to switch language for cases when language is not part of url for example, because if so, changing to language-aware itself should be act of switching language. I see no reason using that view for unnecessary redirect since I have language-aware URLs.

The suggestion is to stop redirecting from / to language-aware URL when user has language set in session or in cookies, even if user's language is not equal to default one. Am I right?

Example. The site is supporting two languages: English and Russian. English is default one.
We want to serve default English language at root path /, and Russian at /ru/. We also want to automatically redirect the user to his language, so we set SOLID_I18N_USE_REDIRECTS = True.
We want to behave it in the following manner:

  • if user doesn't have language set in his session or cookies, then we will create redirect to corresponding language (only if HTTP ACCEPT_LANGUAGE is not equal to default one)
  • (new behaviour) but if user do have language set in his session or cookies, then we stop using redirects at all. I.e. we render content at / even if user's language is not equal to default language.

Is this correct?
/cc @pierreben

@st4lk
Copy link
Owner

st4lk commented Jan 10, 2017

@pierreben

Moreover, your feedback made me think about what would happened if the crawler doesn't support the cookies. In this case it is certainly possible that it can never crawl the pages of the default language because it will always encounter a 302 redirect on /.
But, I think that this drawback also occurs when the SOLID_I18N_USE_REDIRECTS is activated because the only way to switch to the default language is to use the set_language view if the crawler has a HTTP_ACCEPT_LANGUAGE that differs from DEFAULT_LANGUAGE.

Right, such case can happen, so SOLID_I18N_USE_REDIRECTS = True should be used with caution. Javascript solution can be a good idea.

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