Copied to clipboard

Flag this post as spam?

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


  • David Peck 642 posts 1683 karma points c-trib
    1 week ago
    David Peck
    0

    Fallback to content in another language (not resolved)

    Hi all,

    I'm struggling to get my head around language fallbacks. I understand that where a property is a string (and possibly others) you can fallback to another language if the property the property isn't populated.

    However, I would like to have a MNTP and if the selected content is not published in the desired language then the content which is the fallback is selected.

    For example.

    1. My default language is en-GB, I also have nl-NL and nl-BE. nl-BE is set to fallback to nl-NL.
    2. I have a home page published in all 3 languages, with a MNTP property called quiz. The quiz property has a piece of content called 'My Quiz' selected.
    3. 'My Quiz' is published in en-GB and nl-NL only.
    4. This is set: _variationContextAccessor.VariationContext = new VariationContext("nl-BE");

    When I ask for homePage.quiz I'm hoping for the variation in nl-NL because an nl-BE variation doesn't exist (and nl-NL is the fallback language ). Instead I'm given en-GB because that is the default language.

    Is what I've described above the expected behaviour and if so is there a workaround?

    TIA

  • Dan Diplo 1524 posts 6000 karma points MVP 4x c-trib
    1 week ago
    Dan Diplo
    100

    In Settings > Languages have you set the fallback language for nl-BE to be nl-NL?

  • David Peck 642 posts 1683 karma points c-trib
    1 week ago
    David Peck
    0

    Hi Dan.

    So this is already done. It works for a text field (e.g. heading is blank in nl-BE so fallback to nl-NL where it is populated). The problem I am experiencing is when there is no nl-BE content published. Under that circiumstance the UmbracoHelper and the Models Builder returns the en-GB version of the content.

    I suspect model.ValueFor(...) only works for strings and numbers, but not for IPublishedContent, and that Content Cache (when working with VariationContext) still doesn't facilitate fallbacks.

    That might be intended behaviour, e.g. if you didn't want a page to be available in nl-BE although that wouldn't be 1-to-1 translation.

    It could be my implementation. I have had to simplify it for this post, so if you think it should work as I desire then I'll take another look.

  • David Peck 642 posts 1683 karma points c-trib
    1 week ago
    David Peck
    0
     variationContextAccessor.VariationContext = new VariationContext("nl-BE");
     IPublishedContent testQuestion0 = Umbraco.Content(1284);
    

    1284 is published in en-GB and nl-NL. testQuestion0 gives me an IPublishedContent but with a Name equal to null and .IsPublished() is false.

    and to be clear:

     variationContextAccessor.VariationContext = new VariationContext("en-GB");
     IPublishedContent testQuestion0 = Umbraco.Content(1284);
    

    This gives me an IPublishedContent with a Name equal to Test Question.

Please Sign in or register to post replies

Write your reply to:

Draft