new localizer works

This commit is contained in:
2022-12-12 11:30:58 +01:00
parent 16ce8b442b
commit 1909746405
3 changed files with 10 additions and 2 deletions
+1 -2
View File
@@ -20,8 +20,7 @@ public class ConfigurationLocalizer : Localizer
protected override Translation LoadTranslation(string key)
{
string normalizedKey = key.Replace(".", ":");
IConfigurationSection section = _configuration.GetSection($"Zero:Localization:{normalizedKey}");
IConfigurationSection section = _configuration.GetSection($"Zero:Localization:{key}");
if (section == null)
{
+8
View File
@@ -3,6 +3,14 @@ using Microsoft.Extensions.Localization;
namespace zero.Localization;
public class StringLocalizer<T> : StringLocalizer, IStringLocalizer<T>
{
public StringLocalizer(ILocalizer localizer) : base(localizer)
{
}
}
public class StringLocalizer : IStringLocalizer
{
private readonly ILocalizer _localizer;
@@ -20,6 +20,7 @@ internal class ZeroLocalizationModule : ZeroModule
services.AddScoped<ICultureService, CultureService>();
services.AddScoped<ILocalizer, ConfigurationLocalizer>();
services.AddScoped<IStringLocalizer, StringLocalizer>();
services.AddScoped(typeof(IStringLocalizer<>), typeof(StringLocalizer<>));
services.Configure<RazorViewEngineOptions>(opts => opts.ViewLocationExpanders.Add(new LanguageViewLocationExpander(LanguageViewLocationExpanderFormat.Suffix)));
services.AddSingleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>();