Skip to content

Instantly share code, notes, and snippets.

@trnktms
Last active June 3, 2021 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/ceefd77f0132cec488dc43a7ff64c68e to your computer and use it in GitHub Desktop.
Save trnktms/ceefd77f0132cec488dc43a7ff64c68e to your computer and use it in GitHub Desktop.
public class Startup
{
private static readonly string _defaultLanguage = "en";
private static readonly List<CultureInfo> _supportedCultures = new List<CultureInfo> { new CultureInfo(_defaultLanguage) };
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers();
// Dictionary registrations
services.Configure<SitecoreLocalizerOptions>(options => options.Cultures = _supportedCultures);
services.AddHttpClient<ISitecoreLocalizer, SitecoreLocalizer>("sitecoreLocalizer", client =>
{
client.BaseAddress = Configuration.DictionaryServiceUri;
});
services.AddTransient<ISitecoreLocalizer, SitecoreLocalizer>();
services.AddTransient<IStringLocalizer, SitecoreLocalizer>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
...
// Open the endpoint to Sitecore CM publishing web hook
endpoints.MapControllerRoute(
"localization",
"api/localization/reload",
new { controller = "Localization", action = "Reload" }
);
...
});
// Initialize the dictionary cache
Task.Run(async () => await app.ApplicationServices.GetRequiredService<ISitecoreLocalizer>().Reload()).Wait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment