Open hovi opened 7 years ago
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: https://github.com/pierreben/django-solid-i18n-urls/commit/bba183aef7272796ac609b100c7535669f72c4da. If you wish, I can add an option in settings and write the missing tests.
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.
@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.
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 ?
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:
/
even if user's language is not equal to default language.Is this correct? /cc @pierreben
@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 theset_language
view if the crawler has aHTTP_ACCEPT_LANGUAGE
that differs fromDEFAULT_LANGUAGE
.
Right, such case can happen, so SOLID_I18N_USE_REDIRECTS = True
should be used with caution. Javascript solution can be a good idea.
Re using
SOLID_I18N_USE_REDIRECTS
andset_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 ofprocess_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
.