Skip to content

Add Fallback.ToDefaultLanguage to get fallback value from the default language #8349

@ronaldbarendse

Description

@ronaldbarendse

As discussed in modelsbuilder/ModelsBuilder.Original#206 and modelsbuilder/ModelsBuilder.Original#235, the current options to get fallback values are quite minimal or very verbose. Some things can be fixed within Models Builder (e.g. generating additional extension methods accepting fallback options), customizing the model classes or even replacing the IPublishedValueFallback.

One thing that might be a good addition is adding Fallback.ToDefaultLanguage, so you can get a fallback value from the default language without configuring the fallback chain on the languages themselfs.

The default PublishedValueFallback implementation already depends on ILocalizationService, so getting the default langauge can be done using _localizationService.GetDefaultLanguageIsoCode():

public PublishedValueFallback(ServiceContext serviceContext, IVariationContextAccessor variationContextAccessor)
{
_localizationService = serviceContext.LocalizationService;
_variationContextAccessor = variationContextAccessor;
}

Looking at the code and comments in this class, it already requires some attention. Most of the logic can be moved into a base class, so replacing it with a custom implementation (e.g. using a custom language fallback chain or recurse ancestors & languages) can be written a lot easier!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions