2025-09-25 00:09:19 +02:00
|
|
|
using FluentValidation;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Localization;
|
2022-12-12 11:22:21 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
2022-12-07 14:05:11 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-12-12 11:22:21 +01:00
|
|
|
using Microsoft.Extensions.Localization;
|
2022-12-07 14:05:11 +01:00
|
|
|
|
|
|
|
|
namespace zero.Localization;
|
|
|
|
|
|
|
|
|
|
internal class ZeroLocalizationModule : ZeroModule
|
|
|
|
|
{
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
2022-12-09 17:14:45 +01:00
|
|
|
// hint: think about using https://github.com/nuages-io/nuages-localization
|
|
|
|
|
|
2025-09-25 00:09:19 +02:00
|
|
|
ValidatorOptions.Global.LanguageManager.AddGermanOverrides();
|
|
|
|
|
|
2022-12-07 14:05:11 +01:00
|
|
|
services.AddScoped<ICultureResolver, CultureResolver>();
|
|
|
|
|
services.AddScoped<ICultureService, CultureService>();
|
2022-12-12 11:22:21 +01:00
|
|
|
services.AddScoped<ILocalizer, ConfigurationLocalizer>();
|
|
|
|
|
services.AddScoped<IStringLocalizer, StringLocalizer>();
|
2022-12-12 11:30:58 +01:00
|
|
|
services.AddScoped(typeof(IStringLocalizer<>), typeof(StringLocalizer<>));
|
2022-12-07 15:20:53 +01:00
|
|
|
|
2022-12-12 11:22:21 +01:00
|
|
|
services.Configure<RazorViewEngineOptions>(opts => opts.ViewLocationExpanders.Add(new LanguageViewLocationExpander(LanguageViewLocationExpanderFormat.Suffix)));
|
|
|
|
|
services.AddSingleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>();
|
|
|
|
|
services.AddTransient<IHtmlLocalizer, HtmlLocalizer>();
|
|
|
|
|
services.AddTransient<IViewLocalizer, ViewLocalizer>();
|
|
|
|
|
|
|
|
|
|
services.AddLocalization();
|
|
|
|
|
|
|
|
|
|
|
2022-12-07 15:20:53 +01:00
|
|
|
services.AddOptions<LocalizationOptions>().Bind(configuration.GetSection("Zero:Localization")).Configure(opts =>
|
|
|
|
|
{
|
|
|
|
|
opts.FilePath = "Config/texts.json";
|
|
|
|
|
});
|
2022-12-07 14:05:11 +01:00
|
|
|
}
|
|
|
|
|
}
|