54 lines
1.9 KiB
C#
54 lines
1.9 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.Collections.Generic;
|
|
using System.Globalization;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace RazorWebSite
|
|
{
|
|
public class StartupDataAnnotations
|
|
{
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddLocalization(options => options.ResourcesPath = "Resources");
|
|
|
|
services
|
|
.AddMvc()
|
|
.AddViewLocalization()
|
|
.AddDataAnnotationsLocalization((options) =>
|
|
{
|
|
options.DataAnnotationLocalizerProvider =
|
|
(modelType, stringLocalizerFactory) => stringLocalizerFactory.Create(typeof(SingleType));
|
|
})
|
|
.SetCompatibilityVersion(CompatibilityVersion.Latest);
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("en-US", "en-US"),
|
|
SupportedCultures = new List<CultureInfo>
|
|
{
|
|
new CultureInfo("en-US")
|
|
},
|
|
SupportedUICultures = new List<CultureInfo>
|
|
{
|
|
new CultureInfo("en-US")
|
|
}
|
|
});
|
|
app.UseStaticFiles();
|
|
|
|
// Add MVC to the request pipeline
|
|
app.UseMvcWithDefaultRoute();
|
|
}
|
|
}
|
|
}
|