ILanguageSelector was replaced with LoaderOptions in the API in all methods where you load content. New overloads have also been added that take a CultureInfo to make it easier to load a specific language. Methods that previously used LanguageSelector, such as GetDefault or CreateLanguageBranch, now only accept CultureInfo to simplify the usage of the API. Behind the scenes, all methods have the same behavior as before but most of the code has been rewritten to support the new projects feature.
T Get<T>( Guid contentGuid) where T : IContentData;
T Get<T>( Guid contentGuid, CultureInfo language) where T : IContentData ;
T Get<T>( Guid contentGuid, LoaderOptions settings) where T : IContentData ;
In IContentRepository, all methods where you create content for a specific language now only take a CultureInfo:
T GetDefault<T>(ContentReference parentLink, CultureInfo language) where T : IContentData;
To make sure it is a smooth upgrade the LanguageSelector inherits LoaderOptions and works pretty much as before if you choose to continue using it.
public class LanguageSelector : LoaderOptions, ILanguageSelector
Since language handling often is handled by EPiServer and not by the code in the templates, many sites will just work after a recompilation. What may require more changes are unit tests where you are using fakes/mocks, but in many cases it is just a case of replacing mocks of ILanguageSelector with LoaderOptions or LanguageSelector. An example of mocking using Moq:
_contentRepository.Setup(repo => repo.Get<IContent>( It.IsAny<ContentReference>(), It.IsAny<LoaderOptions >())).Returns(childContent);
The interface ILanguageSelector has been simplified. Now it only contains a single property Language of type CultureInfo. This means that content provider implementations no longer need to call any methods on ILanguageSelector to decide which language version to return. Instead, they can just return the language version specified by ILanguageSelector.Language. If CultureInfo.InvariantCulture is passed in the provider should return content in the master language. If the content does not exist on the specified language then the master language should be returned.
ContentReference have a property GetPublishedOrLatest that loads the published version or the latest version, if no published version exists. When using this property with language fallback, it previously only loaded published versions in the fallback chain. This have been corrected and it now picks the published or latest version in the fallback chain as well. This property is normally not used in templates.
In previous versions of CMS it was possible to cast the passed in LanguageSelector to ILanguageSelectionSource after content retrieval. That interface contained information on why the content was selected, such as if the content was selected due to language fallback or replacement rules. The same information can now be retrieved after content retrieval by calling MatchLanguageSettings on IContentLanguageSettingsHandler passing in the retrieved content instance and the requested language, as:
var selectionSource = ServiceLocator.Current.GetInstance<IContentLanguageSettingsHandler>().MatchLanguageSettings(content, "sv");
Updated about 1 year ago