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 690 posts 1896 karma points c-trib
    Jun 10, 2021 @ 10:06
    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 1554 posts 6205 karma points MVP 6x c-trib
    Jun 10, 2021 @ 10:21
    Dan Diplo
    100

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

  • David Peck 690 posts 1896 karma points c-trib
    Jun 10, 2021 @ 10:24
    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 690 posts 1896 karma points c-trib
    Jun 10, 2021 @ 11:06
    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.

  • Thomas Beckert 193 posts 469 karma points
    Apr 24, 2022 @ 12:58
    Thomas Beckert
    0

    If found this solution for me - this works in umbraco 9. I guess only the partialview rendering has to be adjusted for lower versions.

    First import Namespace:

    @using Newtonsoft.Json.Linq;
    

    After that, load the content of your grid into a JObject. In my case, the Popertyname Alias is simply "grid".

    JObject grid = Model.Value<JObject>("grid");
    

    Now you can check the grid for content and otherwise just do a fallback by calling your partialview for rendering the grid directly with the value of your fallback language (in my case "de"):

    @if (Model.HasValue("grid") && grid.SelectTokens("sections[*].rows[*].areas[*].controls").Any()){
        @Html.GetGridHtml(Model, "grid")
    }
    else
    {
        @await Html.PartialAsync("grid/bootstrap3", Model.Value("grid", "de"))
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft