KenticoDevTrev/PartialWidgetPage

ActualUrl in PartialWidgetPageModel returns URL with wrong culture code

Closed this issue · 12 comments

On my site, there are three supported languages: English US (default), English UK and German. In the page application of Kentico there are a lot of pages, which only have a default version, because the translation of the content is either not necessary or resolved by localization macros.
The URL returned by ActualUrl always includes "en-US" instead of the current culture code.
At the moment, I have overridden the getter of ActualUrl:

var cultureCode = HttpContext.Current.Request.RequestContext.RouteData.Values["culture"]?.ToString();
if (cultureCode != null)
{
    var culture = new CultureInfo(cultureCode);
    url = Regex.Replace(url, LocalizationContext.CurrentCulture.CultureCode, culture.Name, RegexOptions.IgnoreCase);
}

LocalizationContext.CurrentCulture.CultureCode is always "en-US" in my case.

With this one, are you setting the System Culture? You usually need to set that somehow for the LocalizationContext.CurrentCulture.CultureCode to work.

  CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL");

Yes, when I check the CurrentCulture before accessing the ActualUrl then CurrentCulture is "de-DE", but in the ActualUrl it is "en-US".

I have the culture in the URL, like https://localhost/de-DE/... I don't use your dynamic routing system for resolving the URLs. A route handler is setting the CurrentCulture by accessing an URL with culture code.

The problem is that LocalizationContext.CurrentCulture.CultureCode always returns en-US although Thread.CurrentThread.CurrentCulture is de-DE. I followed the instructions on https://devnet.kentico.com/questions/how-to-get-culture-code-of-current-request, and the problem exists only in PartialWidgetPages. Normal pages work as expected.

The URL pattern for the partial widget page type is "/{%DocumentCulture%}/Components/EmployeeHighlight/{%NodeGUID%}"

Note: There are no culture specific pages in the page tree. All pages are created with the default culture (en-US). By accessing the pages with a different culture their content is localized by resource strings. Because of that LocalizationContext.CurrentCulture.CultureCode seems to be always en-US, but Thread.CurrentThread.CurrentCulture is correctly set by the route handler.

As a workaround I currently overwritten the ActualUrl getter and replace the culture in the URL with the correct one from the request (see my first post). But this should be always done, because the Thread.CurrentThread.CurrentCulture is relevant and not the other one. There are many cases where independent culture-specific pages are not necessary, because there aren't editor fields or translation is done by resource strings.

Not sure how i would go about accomplishing your request in terms of a full fix. You will just need to pass it the proper URL path instead of a nodealiaspath in your request, and add the culture in there, that's the only way for it to know where to pull it in in the case where the culture you request isn't found.