Site structure
Version 7.x > Site structure > Losing selected culture when "Combine with default culture" option is used View modes: 
User avatar
Member
Member
kevin-revie - 9/20/2013 12:43:36 PM
   
Losing selected culture when "Combine with default culture" option is used
Our Kentico 7 Web site has a default culture of "en-US". We only have a few pages in the "es-MX" culture. The client wants to use pages in English when there is no Spanish version available so we are using the "Combine with default culture" option. The problem is that as soon as the user goes to an English page, then all pages are displayed in English even if there is a Spanish version. The Spanish pages are only displaying if the user doesn't first go to an English page. Is this a bug or am I doing something wrong? If the user selects that they want to view pages in Spanish, then they should get the Spanish version if there is a page in that language.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 9/23/2013 1:39:39 AM
   
RE:Losing selected culture when "Combine with default culture" option is used
Hello,

This behaviour is based on cookies. Do you have cookies enabled in your browser? Are talking about anonymous users or registered users? Did you try it in a different browser?

For me it's working fine... if I switch page e.g. to German, Combine with default culture is enabled... German page, Non existing German version -> English page, and when I switch back to any german page, content is displayed correctly in German again.

Best regards,
Martin Danko

User avatar
Member
Member
kevin-revie - 9/23/2013 8:10:47 AM
   
RE:Losing selected culture when "Combine with default culture" option is used
Yes, I have tried in different browsers and cookies are enabled. This is the exact cookie isn't it?:
CookieHelper.GetValue("CMSPreferredCulture")

As soon as I go to a page that isn't translated, that cookie changes to the default language. Translated pages are then displayed in the default language even if they are translated. I am running v7.0.34.

I did find a work around. As soon as the user selects the language they want, I store that value in my own cookie. I then set my cookie as the culture on every page load. This change appears to have fixed the problem. To help anyone else having the same problem, here is my exact code:

protected void Page_PreRender(Object sender, EventArgs e)
{
//We are going to keep track of the selected language ourselves
if (!String.IsNullOrEmpty(Request["lang"]))
{
CookieHelper.SetValue("SELECTEDCULTURE", Request["lang"].ToString(), DateTime.Now.AddDays(1));
CMS.GlobalHelper.CultureHelper.SetPreferredUICulture(Request["lang"].ToString());
}
setCulture();
}

public void setCulture() {
//get the selected culture in our cookie. default to the default culture.
string currentCulture = (CookieHelper.GetValue("SELECTEDCULTURE") == null ? "en-US" : CookieHelper.GetValue("SELECTEDCULTURE").ToString());
//change every Kentico culture variable we can
repSubItems.CultureCode = currentCulture;
CMSRepeater1.CultureCode = currentCulture;
Page.Culture = currentCulture;
CMSContext.CurrentDocument.DocumentCulture = currentCulture;
CookieHelper.SetValue("CMSPreferredCulture", currentCulture, DateTime.Now.AddDays(3));
CultureHelper.SetPreferredCulture(currentCulture);
}

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 9/30/2013 4:07:35 AM
   
RE:Losing selected culture when "Combine with default culture" option is used
Hello,

The behaviour you are describing is not a standard behaviour of Kentico... the language cookie shouldn't be overwritten.

Do you have any customizations which could influence this? I would also recommend you to try to install a clean installation of Kentico to see if this behaviour will persist in your case. I wasn't able to reproduce it on default Kentico installation.

Best regards,
Martin Danko