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.
My default language is en-GB, I also have nl-NL and nl-BE. nl-BE is set to fallback to nl-NL.
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.
'My Quiz' is published in en-GB and nl-NL only.
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?
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.
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"):
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.
en-GB
, I also havenl-NL
andnl-BE
.nl-BE
is set to fallback tonl-NL
.quiz
. Thequiz
property has a piece of content called 'My Quiz' selected.en-GB
andnl-NL
only._variationContextAccessor.VariationContext = new VariationContext("nl-BE");
When I ask for
homePage.quiz
I'm hoping for the variation innl-NL
because annl-BE
variation doesn't exist (andnl-NL
is the fallback language ). Instead I'm givenen-GB
because that is the default language.Is what I've described above the expected behaviour and if so is there a workaround?
TIA
In Settings > Languages have you set the fallback language for
nl-BE
to benl-NL
?Hi Dan.
So this is already done. It works for a text field (e.g. heading is blank in
nl-BE
so fallback tonl-NL
where it is populated). The problem I am experiencing is when there is nonl-BE
content published. Under that circiumstance the UmbracoHelper and the Models Builder returns theen-GB
version of the content.I suspect
model.ValueFor(...)
only works for strings and numbers, but not forIPublishedContent
, 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.
1284 is published in
en-GB
andnl-NL
.testQuestion0
gives me anIPublishedContent
but with aName
equal tonull
and.IsPublished()
isfalse
.and to be clear:
This gives me an
IPublishedContent
with aName
equal toTest Question
.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:
After that, load the content of your grid into a JObject. In my case, the Popertyname Alias is simply "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"):
is working on a reply...