String-Lokalisierer für Model.resx im Common-Projekt hinzugefügt.

This commit is contained in:
Developer 02 2024-06-25 13:07:02 +02:00
parent dd6ab13e6e
commit e264a10a36
7 changed files with 33 additions and 16 deletions

View File

@ -214,12 +214,15 @@
<DependentUpon>Model.en.resx</DependentUpon> <DependentUpon>Model.en.resx</DependentUpon>
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile> </Compile>
<Compile Include="Strings\Model.Designer.vb"> <Compile Include="Strings\Model.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Model.resx</DependentUpon> <DependentUpon>Model.resx</DependentUpon>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile> </Compile>
<Compile Include="Strings\Model.vb" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="My Project\licenses.licx" /> <EmbeddedResource Include="My Project\licenses.licx" />
@ -256,11 +259,13 @@
<Generator>PublicResXFileCodeGenerator</Generator> <Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Model.en.Designer.vb</LastGenOutput> <LastGenOutput>Model.en.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace> <CustomToolNamespace>My.Resources</CustomToolNamespace>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Strings\Model.resx"> <EmbeddedResource Include="Strings\Model.resx">
<CustomToolNamespace>My.Resources</CustomToolNamespace> <CustomToolNamespace>My.Resources</CustomToolNamespace>
<Generator>PublicResXFileCodeGenerator</Generator> <Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Model.Designer.vb</LastGenOutput> <LastGenOutput>Model.Designer.vb</LastGenOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,3 @@
Public Class Model
End Class

View File

@ -100,19 +100,6 @@ namespace EnvelopeGenerator.Domain.Entities
[NotMapped] [NotMapped]
public bool IsAlreadySent => Status > (int) Constants.EnvelopeStatus.EnvelopeSaved; public bool IsAlreadySent => Status > (int) Constants.EnvelopeStatus.EnvelopeSaved;
[NotMapped]
public string? StatusTranslated => Model.ResourceManager.GetString(Status.ToString());
[NotMapped]
public string? ContractTypeTranslated
{
get
{
string? oContractType = ContractType.ToString();
return oContractType is null ? default : Model.ResourceManager.GetString(oContractType);
}
}
public IEnumerable<EnvelopeDocument>? Documents { get; set; } public IEnumerable<EnvelopeDocument>? Documents { get; set; }
public IEnumerable<EnvelopeHistory>? History { get; set; } public IEnumerable<EnvelopeHistory>? History { get; set; }

View File

@ -179,6 +179,7 @@
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="frmEnvelopeEditor.resx"> <EmbeddedResource Include="frmEnvelopeEditor.resx">
<DependentUpon>frmEnvelopeEditor.vb</DependentUpon> <DependentUpon>frmEnvelopeEditor.vb</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="frmEnvelopeMainData.en.resx"> <EmbeddedResource Include="frmEnvelopeMainData.en.resx">
<DependentUpon>frmEnvelopeMainData.vb</DependentUpon> <DependentUpon>frmEnvelopeMainData.vb</DependentUpon>

View File

@ -1,5 +1,6 @@
using DigitalData.Core.API; using DigitalData.Core.API;
using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Application.Resources;
using EnvelopeGenerator.Common;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
@ -14,17 +15,24 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
private static readonly Guid L_KEY = Guid.NewGuid(); private static readonly Guid L_KEY = Guid.NewGuid();
private readonly ILogger<LocalizationController> _logger; private readonly ILogger<LocalizationController> _logger;
private readonly IStringLocalizer<Model> _mLocalizer;
private readonly IStringLocalizer<Resource> _localizer; private readonly IStringLocalizer<Resource> _localizer;
private readonly IMemoryCache _cache; private readonly IMemoryCache _cache;
public LocalizationController(ILogger<LocalizationController> logger, IStringLocalizer<Resource> localizer, IMemoryCache memoryCache)
public LocalizationController(
ILogger<LocalizationController> logger,
IStringLocalizer<Resource> localizer,
IMemoryCache memoryCache,
IStringLocalizer<Model> _modelLocalizer)
{ {
_logger = logger; _logger = logger;
_localizer = localizer; _localizer = localizer;
_cache = memoryCache; _cache = memoryCache;
_mLocalizer = _modelLocalizer;
} }
[HttpGet] [HttpGet]
public IActionResult GetAll() => Ok(_cache.GetOrCreate(L_KEY, _ => _localizer.ToDictionary())); public IActionResult GetAll() => Ok(_cache.GetOrCreate(Language ?? string.Empty + L_KEY, _ => _mLocalizer.ToDictionary()));
[HttpGet("lang")] [HttpGet("lang")]
public IActionResult GetLanguage() => Language is null ? NotFound() : Ok(Language); public IActionResult GetLanguage() => Language is null ? NotFound() : Ok(Language);

View File

@ -25,6 +25,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" /> <ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" />
<ProjectReference Include="..\EnvelopeGenerator.Common\EnvelopeGenerator.Common.vbproj" />
<ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" /> <ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" />
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" /> <ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -4,7 +4,9 @@ using DigitalData.UserManager.Application;
using DigitalData.UserManager.Infrastructure.Repositories; using DigitalData.UserManager.Infrastructure.Repositories;
using EnvelopeGenerator.Application; using EnvelopeGenerator.Application;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Localization;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Globalization;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -73,7 +75,17 @@ if (app.Environment.IsDevelopment())
app.UseCors("AllowSpecificOriginsPolicy"); app.UseCors("AllowSpecificOriginsPolicy");
// Localizer // Localizer
app.UseCookieBasedLocalizer("de-DE", "en-US"); string[] supportedCultureNames = { "de-DE", "en-US" };
IList<CultureInfo> list = supportedCultureNames.Select((string cn) => new CultureInfo(cn)).ToList();
CultureInfo cultureInfo = list.FirstOrDefault() ?? throw new ArgumentNullException("supportedCultureNames", "Supported cultures cannot be empty.");
RequestLocalizationOptions requestLocalizationOptions = new RequestLocalizationOptions
{
SupportedCultures = list,
SupportedUICultures = list
};
requestLocalizationOptions.RequestCultureProviders.Add(new QueryStringRequestCultureProvider());
app.UseRequestLocalization(requestLocalizationOptions);
app.UseHttpsRedirection(); app.UseHttpsRedirection();