String-Lokalisierer für Model.resx im Common-Projekt hinzugefügt.
This commit is contained in:
parent
dd6ab13e6e
commit
e264a10a36
@ -214,12 +214,15 @@
|
||||
<DependentUpon>Model.en.resx</DependentUpon>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Include="Strings\Model.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Model.resx</DependentUpon>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Include="Strings\Model.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\licenses.licx" />
|
||||
@ -256,11 +259,13 @@
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Model.en.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Strings\Model.resx">
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Model.Designer.vb</LastGenOutput>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
3
EnvelopeGenerator.Common/Strings/Model.vb
Normal file
3
EnvelopeGenerator.Common/Strings/Model.vb
Normal file
@ -0,0 +1,3 @@
|
||||
Public Class Model
|
||||
|
||||
End Class
|
||||
@ -100,19 +100,6 @@ namespace EnvelopeGenerator.Domain.Entities
|
||||
[NotMapped]
|
||||
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<EnvelopeHistory>? History { get; set; }
|
||||
|
||||
@ -179,6 +179,7 @@
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="frmEnvelopeEditor.resx">
|
||||
<DependentUpon>frmEnvelopeEditor.vb</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="frmEnvelopeMainData.en.resx">
|
||||
<DependentUpon>frmEnvelopeMainData.vb</DependentUpon>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using DigitalData.Core.API;
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using EnvelopeGenerator.Common;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
@ -14,17 +15,24 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
||||
private static readonly Guid L_KEY = Guid.NewGuid();
|
||||
|
||||
private readonly ILogger<LocalizationController> _logger;
|
||||
private readonly IStringLocalizer<Model> _mLocalizer;
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
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;
|
||||
_localizer = localizer;
|
||||
_cache = memoryCache;
|
||||
_mLocalizer = _modelLocalizer;
|
||||
}
|
||||
|
||||
[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")]
|
||||
public IActionResult GetLanguage() => Language is null ? NotFound() : Ok(Language);
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Application\EnvelopeGenerator.Application.csproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Common\EnvelopeGenerator.Common.vbproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" />
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Infrastructure\EnvelopeGenerator.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -4,7 +4,9 @@ using DigitalData.UserManager.Application;
|
||||
using DigitalData.UserManager.Infrastructure.Repositories;
|
||||
using EnvelopeGenerator.Application;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Globalization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -73,7 +75,17 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseCors("AllowSpecificOriginsPolicy");
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user