Search code examples
c#.netmultilingualculturekentico

Kentico Cultures not working after navigating


I'm currently working on rolling out a Korean version of a site in Kentico 8.2 and working with local and dev versions of the site.

I can get a page to load in Korean and even some subsequent pages to load in Korean while navigating. Usually the third or fourth page I navigate to will revert back to English. I can re-add the query string ?lang=ko-kr or add /ko-kr/ to the URL (depending on what setting I'm trying at the time) to get that page to load in Korean (verifying it exists). It doesn't seem to matter what page I start on or what page(s) I navigate to.

I've tried a combination of the below settings:

  • Forcing Domain Culture (only) in Settings/URLs and SEO
  • Use Language prefix for URLs (with and without Allow URLs without language prefixes) in Settings/URLs and SEO
  • Changing visitor culture to Automatic (Sites/General)

With these variety of settings, I've tried appending ?lang=ko-kr or used domain/ko-kr/rest-of-url to get a page to load in Korean (matching the appropriate setting).

I've tried other things to see if they're interfering, such as:

  • Language setting in my browser changed to Korean to see if this was overriding anything.
  • Run in incognito mode and cleared cache/cookies to see if these were possible issues.
  • Restarting the server after changing settings.
  • Verifying custom URLs aren't interfering (not set)

I've been searching through Kentico Forums, here on SO, and Googling a variety of search terms with no luck. According to what I've found, these few settings are all that is needed. There's not much addressing these issues, as most results return the normal documentation on how to implement multiple languages on the site.

I've been stuck on this for a few days and feel like I'm missing something quite obvious... it shouldn't be this difficult, should it?


Solution

  • I was able to resolve this issue by setting (Settings > URLs and SEO under heading SEO - Cultures):

    Forcing Domain Culture (unchecked) Use Language prefix for URLs (checked) Allow URLs without language prefixes (unchecked)

    Whenever we were retrieving NodeAliasPath the URL did not include the culture code. It would retain the current language for a few page loads but would eventually revert to the default language (English). Adding the below function around uses of NodeAliasPath fixed the issue.

    public static string GetCultureURL(string url)
    {
      url = url.TrimStart('~');
    
      string output = url;
    
      if (CMS.Localization.LocalizationContext.CurrentCulture.CultureCode.ToLower() != "en-us")
        output = "/" + CMS.Localization.LocalizationContext.CurrentCulture.CultureCode + url;
    
      return output.ToLower();
    }
    

    The CMS likes to insert a tilde (~) for links selected with the link selector so I had to trim it from URLs. Because English is the default language (and it was requested to have English URLs plain), I had an if statement skip the addition of /en-us to the front of URLs.

    It's also not necessary to lowercase the URL, so the function could be reduced to even further.