Read supported cultures from appsettings.json
This commit is contained in:
parent
437170671f
commit
2924e7849f
|
@ -1,14 +1,43 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
|
using Oqtane.Infrastructure.Localization;
|
||||||
|
|
||||||
namespace Oqtane.Extensions
|
namespace Oqtane.Extensions
|
||||||
{
|
{
|
||||||
public static class ApplicationBuilderExtensions
|
public static class ApplicationBuilderExtensions
|
||||||
{
|
{
|
||||||
|
private static readonly string DefaultCultureKey = "Localization:DefaultCulture";
|
||||||
|
private static readonly string SupportedCulturesKey = "Localization:SupportedCultures";
|
||||||
|
|
||||||
|
public static IApplicationBuilder UseOqtaneLocalization(this IApplicationBuilder app)
|
||||||
|
{
|
||||||
|
var configuration = app.ApplicationServices.GetService<IConfiguration>();
|
||||||
|
var defaultCulture = configuration.GetSection(DefaultCultureKey).Value;
|
||||||
|
var supportedCultures = configuration.GetSection(SupportedCulturesKey).Get<string[]>();
|
||||||
|
if (supportedCultures.Length > 0)
|
||||||
|
{
|
||||||
|
LocalizationSettings.SupportedCultures.AddRange(supportedCultures);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalizationSettings.DefaultCulture = defaultCulture;
|
||||||
|
CultureInfo.CurrentUICulture = new CultureInfo(defaultCulture);
|
||||||
|
|
||||||
|
app.UseRequestLocalization(options => {
|
||||||
|
options.SetDefaultCulture(defaultCulture)
|
||||||
|
.AddSupportedUICultures(supportedCultures)
|
||||||
|
.AddSupportedUICultures(supportedCultures);
|
||||||
|
});
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder ConfigureOqtaneAssemblies(this IApplicationBuilder app, IWebHostEnvironment env)
|
public static IApplicationBuilder ConfigureOqtaneAssemblies(this IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
var startUps = AppDomain.CurrentDomain
|
var startUps = AppDomain.CurrentDomain
|
||||||
|
|
|
@ -13,6 +13,6 @@ namespace Oqtane.Infrastructure.Localization
|
||||||
|
|
||||||
public static string DefaultCulture { get; set; }
|
public static string DefaultCulture { get; set; }
|
||||||
|
|
||||||
public static IList<string> SupportedCultures { get; set; }
|
public static List<string> SupportedCultures { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -17,7 +16,6 @@ using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Oqtane.Extensions;
|
using Oqtane.Extensions;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using Oqtane.Infrastructure.Localization;
|
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
using Oqtane.Services;
|
using Oqtane.Services;
|
||||||
|
@ -55,7 +53,6 @@ namespace Oqtane
|
||||||
{
|
{
|
||||||
// Register localization services
|
// Register localization services
|
||||||
services.AddLocalization(options => options.ResourcesPath = "Resources");
|
services.AddLocalization(options => options.ResourcesPath = "Resources");
|
||||||
CultureInfo.CurrentUICulture = new CultureInfo(LocalizationSettings.DefaultCulture);
|
|
||||||
|
|
||||||
services.AddServerSideBlazor();
|
services.AddServerSideBlazor();
|
||||||
|
|
||||||
|
@ -232,8 +229,8 @@ namespace Oqtane
|
||||||
// to allow install middleware it should be moved up
|
// to allow install middleware it should be moved up
|
||||||
app.ConfigureOqtaneAssemblies(env);
|
app.ConfigureOqtaneAssemblies(env);
|
||||||
|
|
||||||
app.UseRequestLocalization(options => options
|
// Allow oqtane localization middleware
|
||||||
.AddSupportedUICultures(LocalizationSettings.SupportedCultures.ToArray()));
|
app.UseOqtaneLocalization();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
|
@ -11,5 +11,9 @@
|
||||||
"DefaultTheme": "",
|
"DefaultTheme": "",
|
||||||
"DefaultLayout": "",
|
"DefaultLayout": "",
|
||||||
"DefaultContainer": ""
|
"DefaultContainer": ""
|
||||||
|
},
|
||||||
|
"Localization": {
|
||||||
|
"DefaultCulture": "en-US",
|
||||||
|
"SupportedCultures": []
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user