Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Crook 26 posts 158 karma points
    Jul 21, 2023 @ 06:04
    Steve Crook
    0

    Wrong culture in some parts of page

    I've got a multi-language v10 site with English as the default language, and all other languages having English as the fallback language. I'm seeing some strange behaviour on the non-English page variants. On these pages, the main content of the page - anything rendered by RenderBody() in my master.cshtml - is in the correct language. But anything else, like the page names and URLs in my site menu, which is rendered by @await Html.PartialAsync("~/Views/Partials/mainNavigation.cshtml"), is in English.

    If I change the fallback language for any of the non-English languages to none, the property values are in the correct language. I've checked System.Threading.Thread.CurrentThread.CurrentCulture.Name at all points in my templates and it is always set to the page language.

    What could be causing the property values to be returned in the fallback language, instead of the page language?

  • Steve Crook 26 posts 158 karma points
    Jul 21, 2023 @ 08:49
    Steve Crook
    101

    I had two problems here:

    For the menu, I needed to get the current culture from System.Globalization.CultureInfo.CurrentCulture.Name and then use IPublishedContent.Name(string culture) and IPublishedContent.Url(string culture) instead of the parameterless versions, which were returning the fallback values.

    For my other templates which were getting site-wide settings from the home page, I had to do this before getting a reference to my home page using the AncestorOrSelf method:

    @inject IVariationContextAccessor _variationContextAccessor
    @{
        _variationContextAccessor.VariationContext = new VariationContext(System.Globalization.CultureInfo.CurrentCulture.Name);
        Home homePage = Model.AncestorOrSelf<Home>();
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft