36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.Linq;
|
|
using Microsoft.AspNet.Mvc.Razor;
|
|
using Microsoft.Framework.DependencyInjection;
|
|
using Microsoft.Framework.DependencyInjection.Extensions;
|
|
using Microsoft.Framework.WebEncoders;
|
|
|
|
namespace Microsoft.AspNet.Mvc.Localization.Internal
|
|
{
|
|
public static class MvcLocalizationServices
|
|
{
|
|
public static void AddLocalizationServices(
|
|
IServiceCollection services,
|
|
LanguageViewLocationExpanderFormat format)
|
|
{
|
|
services.Configure<RazorViewEngineOptions>(
|
|
options =>
|
|
{
|
|
options.ViewLocationExpanders.Add(new LanguageViewLocationExpander(format));
|
|
},
|
|
DefaultOrder.DefaultFrameworkSortOrder);
|
|
|
|
services.TryAdd(ServiceDescriptor.Singleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>());
|
|
services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>)));
|
|
services.TryAdd(ServiceDescriptor.Transient<IViewLocalizer, ViewLocalizer>());
|
|
if (!services.Any(sd => sd.ServiceType == typeof(IHtmlEncoder)))
|
|
{
|
|
services.TryAdd(ServiceDescriptor.Instance<IHtmlEncoder>(HtmlEncoder.Default));
|
|
}
|
|
|
|
services.AddLocalization();
|
|
}
|
|
}
|
|
} |