-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathStartup.cs
54 lines (47 loc) · 2.16 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Localization.Drivers;
using OrchardCore.Localization.Services;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
namespace OrchardCore.Localization
{
/// <summary>
/// Represents a localization module entry point.
/// </summary>
public class Startup : StartupBase
{
public override int ConfigureOrder => -100;
/// <inheritdocs />
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDisplayDriver<ISite>, LocalizationSettingsDisplayDriver>();
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<ILocalizationService, LocalizationService>();
services.AddPortableObjectLocalization(options => options.ResourcesPath = "Localization");
services.Replace(ServiceDescriptor.Singleton<ILocalizationFileLocationProvider, ModularPoFileLocationProvider>());
}
/// <inheritdocs />
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
var localizationService = serviceProvider.GetService<ILocalizationService>();
var defaultCulture = localizationService.GetDefaultCultureAsync().GetAwaiter().GetResult();
var supportedCultures = localizationService.GetSupportedCulturesAsync().GetAwaiter().GetResult();
var options = serviceProvider.GetService<IOptions<RequestLocalizationOptions>>().Value;
options.SetDefaultCulture(defaultCulture);
options
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
;
app.UseRequestLocalization(options);
}
}
}