Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.
This topic explains how to configure the initialization of localization providers used by the default LocalizationService in Optimizely CMS. There way to configure localization is through LocalizationOptions or through extension methods AddLocalization or AddEmbeddedLocalization to IServiceCollection during website initialization.
The following sections show how to achieve this.
Note: A large number of providers increases the time needed to find strings. For best performance, keep the number of localization providers to a minimal.
Configuration
You can register localization providers during the configuration phase of the site initialization from the Startup class using IServiceCollection. Or, you can create an initialization module that implements the IConfigurableModule interface and handle the registration in the ConfigureContainer method; either by configuring the LocalizationOptions class or through the AddLocalizationProvider extension method available on the IServiceCollection interface.
The following example shows how to register a localization provider from method ConfigureServices in the Startup class.
services.AddLocalizationProvider<FileXmlLocalizationProvider,
NameValueCollection>(o =>
{
o[FileXmlLocalizationProvider.PhysicalPathKey] = @"c:\temp\resourceFolder";
});
Optimizely also includes a provider for reading localization resources from embedded XML files, called EPiServer.Framework.Localization.XmlResources.EmbeddedXmlLocalizationProviderInitializer.
The following example demonstrates how to add a localization provider that reads all embedded XML localization files from an assembly.
using System;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Framework.Localization;
namespace CodeSamples
{
[InitializableModule]
[ModuleDependency(typeof(FrameworkInitialization))]
public class CustomLocalizationProviderInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
// ClassInMyAssembly can be any class in the Assembly where the resources are embedded
context.Services.AddEmbeddedLocalization<ClassInMyAssembly>();
}
public void Initialize(InitializationEngine context) { }
public void Uninitialize(InitializationEngine context) { }
}
}
ProviderBasedLocalizationService
Note: You can also directly modify LocalizationService through the API of the ProviderBasedLocalizationService, but you should use another method because this API is likely to be deprecated in a future version.
Do you find this information helpful? Please log in to provide feedback.
Last updated: Jul 02, 2021