November Happy Hour will be moved to Thursday December 5th.

Class ProviderBasedLocalizationService

Provider based implementation of LocalizationService. Uses LocalizationProviders to load localized resources.

Inheritance
System.Object
ProviderBasedLocalizationService
Namespace: EPiServer.Framework.Localization
Assembly: EPiServer.Framework.dll
Version: 12.0.3
Syntax
[ServiceConfiguration]
[InitializableModule]
public class ProviderBasedLocalizationService : LocalizationService, IConfigurableModule, IInitializableModule

Constructors

ProviderBasedLocalizationService()

Initializes a new instance of the ProviderBasedLocalizationService class.

Declaration
public ProviderBasedLocalizationService()

ProviderBasedLocalizationService(ResourceKeyHandler)

Initializes a new instance of the ProviderBasedLocalizationService class.

Declaration
public ProviderBasedLocalizationService(ResourceKeyHandler keyHandler)
Parameters
Type Name Description
ResourceKeyHandler keyHandler

The handler used to manipulate resource keys.

ProviderBasedLocalizationService(ResourceKeyHandler, ICurrentCultureAccessor)

Initializes a new instance of the ProviderBasedLocalizationService class.

Declaration
public ProviderBasedLocalizationService(ResourceKeyHandler keyHandler, ICurrentCultureAccessor currentCultureAccessor)
Parameters
Type Name Description
ResourceKeyHandler keyHandler

The handler used to manipulate resource keys.

ICurrentCultureAccessor currentCultureAccessor

The culture accessor used to resolve current culture

Properties

AvailableLocalizations

Gets all available localizations that the LocalizationService has knowledge of.

Declaration
public override IEnumerable<CultureInfo> AvailableLocalizations { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.Globalization.CultureInfo>
Overrides

ProviderList

Gets a list of the current set of LocalizationProvider that are used by the ProviderBasedLocalizationService.

Declaration
public IEnumerable<LocalizationProvider> ProviderList { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<LocalizationProvider>
Remarks

Providers are processed in prioritized order from first to last and will return localized strings from the first provider that returns a value.

Methods

AddProvider(LocalizationProvider)

Adds a LocalizationProvider to the service at the end of the provider list.

Declaration
public void AddProvider(LocalizationProvider provider)
Parameters
Type Name Description
LocalizationProvider provider

The provider that should be added.

ConfigureContainer(ServiceConfigurationContext)

Configure the IoC container before initialization.

Declaration
public void ConfigureContainer(ServiceConfigurationContext context)
Parameters
Type Name Description
ServiceConfigurationContext context

The context on which the container can be accessed.

CreateLocalizationService(ResourceKeyHandler, ICurrentCultureAccessor, LocalizationOptions, IServiceProvider)

Declaration
public static LocalizationService CreateLocalizationService(ResourceKeyHandler keyHandler, ICurrentCultureAccessor currentCultureAccessor, LocalizationOptions localizationOptions, IServiceProvider serviceProvider)
Parameters
Type Name Description
ResourceKeyHandler keyHandler
ICurrentCultureAccessor currentCultureAccessor
LocalizationOptions localizationOptions
System.IServiceProvider serviceProvider
Returns
Type Description
LocalizationService

GetAllStringsByCulture(String, String[], CultureInfo)

Gets all localized strings for the specified culture below the specified key.

Declaration
protected override IEnumerable<ResourceItem> GetAllStringsByCulture(string originalKey, string[] normalizedKey, CultureInfo culture)
Parameters
Type Name Description
System.String originalKey

The original key that was passed into any GetString method.

System.String[] normalizedKey

The originalKey normalized and split into an array

System.Globalization.CultureInfo culture

The requested culture for the localized strings.

Returns
Type Description
System.Collections.Generic.IEnumerable<ResourceItem>

All localized strings below the specified key.

Overrides
See Also
GetStringByCulture(System.String, System.Globalization.CultureInfo)

Initialize(InitializationEngine)

Initializes this instance.

Declaration
public void Initialize(InitializationEngine context)
Parameters
Type Name Description
InitializationEngine context

The context.

Remarks

Gets called as part of the EPiServer Framework initialization sequence. Note that it will be called only once per AppDomain, unless the method throws an exception. If an exception is thrown, the initialization method will be called repeadetly for each request reaching the site until the method succeeds.

InsertProvider(LocalizationProvider)

Adds a LocalizationProvider to the service at the to of the provider list.

Declaration
public void InsertProvider(LocalizationProvider provider)
Parameters
Type Name Description
LocalizationProvider provider

The provider that should be added.

LoadString(String[], String, CultureInfo)

Gets the localized string for the specified key in the specified culture.

Declaration
protected override string LoadString(string[] normalizedKey, string originalKey, CultureInfo culture)
Parameters
Type Name Description
System.String[] normalizedKey

The originalKey normalized and split into an array

System.String originalKey

The original key that was passed into any GetString method.

System.Globalization.CultureInfo culture

The requested culture for the localized string.

Returns
Type Description
System.String

A localized string or null if no resource is found for the given key and culture.

Overrides
See Also
GetStringByCulture(System.String, System.Globalization.CultureInfo)

RemoveProvider(String)

Removes an existing LocalizationProvider from the list of providers for this service.

Declaration
public void RemoveProvider(string name)
Parameters
Type Name Description
System.String name

The name of the provider to remove.

Exceptions
Type Condition
System.ArgumentException

Thrown if no provider with the given name has been added to the service.

Uninitialize(InitializationEngine)

Resets the module into an uninitialized state.

Declaration
public void Uninitialize(InitializationEngine context)
Parameters
Type Name Description
InitializationEngine context

The context.

Remarks

This method is usually not called when running under a web application since the web app may be shut down very abruptly, but your module should still implement it properly since it will make integration and unit testing much simpler.

Any work done by Initialize(InitializationEngine) as well as any code executing on InitComplete should be reversed.

Implements

Extension Methods