How to save language selection in a cookie

May 19, 2013 at 10:47 PM
Hi,
i have a simple question. Is it possible to save language selection from LanguageSelectorForWebForm
into a cookie and when the new page loads LanguageSelectorForWebForm will have language value from a cookie ?


Im doing a 1;1 site translation.
Coordinator
May 20, 2013 at 9:14 AM
Hi!

Yes, it is possible. You would have to download the source code of the package and recompile if of course, because you would need to change the codebehind of the langauge selector (http://polyglot.codeplex.com/SourceControl/latest#Dimi.Polyglot/Web/Frontoffice/LanguageSelectorForWebForm.ascx.cs) to work this way. Then, you would also need to change the razor or xslt scripts to work using cookies instead of reading the language from the URL.

If I may, I would like to advise against this setup though. The method would not work for visitors who block cookies from their browser. Moreover, if you do it so that you remove the language parameter from the URL, you will no longer have unique URLs pointing to each linguistic version of your pages, which is bad for S.E.O. As a matter of fact, best practices tend to point in the opposite direction these days, making the language selection information part of the URL path or domain instead of just a parameter. (I have written about how to make Polyglot work this way: http://dimitros.net/en/blog/betterseowithpolyglot)

Best regards,

Dimitri



May 20, 2013 at 12:29 PM
First of all i want to thank you on your fast reply.

Thank you for directions what would i need to do.

I understand if user blocks cookies this will not work, I was also considering to make a global variable and store selected language in it - do you think is this posible ?

Main reason why I want to set it up like that is simplicity when user needs to edit content it's much simpler this way, but since you are suggesting that this is not a good practice I will reconsider.


Best regards,

Nihad
Coordinator
May 20, 2013 at 1:02 PM
You're welcome!

I'm afraid that storing a global variable on the server would not work. You see, http is stateless, meaning that you will need to use either a cookie or a URL parameter (like the Polyglot package does). Otherwise your system will not "remember" the language each user has selected, even while the users are clicking from one page to the other.

Best regards,

Dimitri