Copied to clipboard

Flag this post as spam?

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


  • Jason 16 posts 166 karma points
    Mar 16, 2024 @ 22:21
    Jason
    0

    Language Fallback Not Working as Expected

    I am using the self-hosted version of Umbraco and have configured the default language of en-US. I have added a second language of en-AU with a fallback to en-US.

    I have configured my document type to allow vary by culture and have configured individual properties in the document type to allow vary by culture.

    I have then created a content item based on that document type for en-US and entered values into all of the fields.

    If I call UmbracoHelper.GetContent(id), then I get the en-US content as expected.

    But if I set the culture to en-AU using VariationContextAccessor.VariationContext = new VariationContext("en-AU") and then try to get the content again using the same GetContent call, then I get a null return value. Should it be falling back to the en-US content or do you have to at least create the en-AU content entry for the fallback to work?

    So, I then create the en-AU variation of the content but only fill in some of the fields, leaving some of the others blank. I was expecting the blank fields to fallback to the en-US values but this doesn't happen...I get the blank values back instead.

    Essentially, I am not able to get any kind of language fallback working. Have I misunderstood how the fallback works, or is there some step that I am missing?

    I should also mention that I am using the Models Builder to generate strongly typed content models and am accessing the content properties from those objects, which are just virtual methods to IPublishedContent.Value() method. Those virtuals pass in an IPublishedValueFallback value so maybe that is the piece that isn't stitched up correctly for me.

  • Jason 16 posts 166 karma points
    Mar 19, 2024 @ 03:43
    Jason
    100

    I figured it out. The issue is that the Models Builder is generating the strongly typed models with individual properties to access the different fields on the content type, but it doesn't provide a value for the fallback, e.g.

    this.Value<string>(_publishedValueFallback, "heading");
    

    When I change this to:

    this.Value<string>(_publishedValueFallback, "heading", fallback: Fallback.ToLanguage);
    

    Then it works as expected and the empty fields fallback to the language selected as the fallback in Umbraco.

    I'm surprised this isn't the default for the strongly typed models created by the Models Builder...then you can control the fallback from the language configuration in the Umbraco backend.

Please Sign in or register to post replies

Write your reply to:

Draft