Hinzugefügt Localizer Dienste für beide api und angular
This commit is contained in:
parent
d94d9f045e
commit
dd6ab13e6e
@ -6,6 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Resources\Model.Designer.vb" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.0" />
|
||||||
@ -41,6 +45,24 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Update="Resources\Model.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Model.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Resources\Model.en.resx">
|
||||||
|
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||||
|
<LastGenOutput>Model.en.Designer.vb</LastGenOutput>
|
||||||
|
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Update="Resources\Model.resx">
|
||||||
|
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||||
|
<LastGenOutput>Model.Designer.cs</LastGenOutput>
|
||||||
|
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Update="Resources\Resource.de-DE.resx">
|
<EmbeddedResource Update="Resources\Resource.de-DE.resx">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|||||||
@ -57,11 +57,8 @@ export class EnvelopeTableComponent {
|
|||||||
|
|
||||||
constructor(private erService: EnvelopeReceiverService) { }
|
constructor(private erService: EnvelopeReceiverService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
async ngOnInit() {
|
||||||
this.erService.getEnvelopeReceiver().subscribe({
|
this.source = await this.erService.getEnvelopeReceiver();
|
||||||
next: res => this.source = res,
|
|
||||||
error: console.error
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
columns: Array<GuiColumn> = [
|
columns: Array<GuiColumn> = [
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
export interface EnvelopeReceiver {
|
|
||||||
name: string | null
|
|
||||||
privateMessage: string | null
|
|
||||||
addedWhen: Date
|
|
||||||
changedWhen: Date | null
|
|
||||||
}
|
|
||||||
@ -1,6 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { EnvelopeTableComponent } from "../../components/envelope-table/envelope-table.component";
|
import { EnvelopeTableComponent } from "../../components/envelope-table/envelope-table.component";
|
||||||
import {MatTabsModule} from '@angular/material/tabs';
|
import { MatTabsModule } from '@angular/material/tabs';
|
||||||
|
import { LocalizationService } from '../../services/localization.service';
|
||||||
|
import { firstValueFrom } from 'rxjs/internal/firstValueFrom';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-envelope',
|
selector: 'app-envelope',
|
||||||
@ -11,4 +13,12 @@ import {MatTabsModule} from '@angular/material/tabs';
|
|||||||
})
|
})
|
||||||
export class EnvelopeComponent {
|
export class EnvelopeComponent {
|
||||||
|
|
||||||
|
private localizer: any = {};
|
||||||
|
|
||||||
|
constructor(private localizationService: LocalizationService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
this.localizer = await this.localizationService.getLocalizer()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import { Injectable, inject } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable, catchError } from 'rxjs';
|
import { Observable, firstValueFrom } from 'rxjs';
|
||||||
import { API_URL } from '../tokens/index';
|
import { API_URL } from '../tokens/index';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@ -14,7 +14,7 @@ export class EnvelopeReceiverService {
|
|||||||
this.url = `${api_url}/envelopereceiver`;
|
this.url = `${api_url}/envelopereceiver`;
|
||||||
}
|
}
|
||||||
|
|
||||||
getEnvelopeReceiver(): Observable<any> {
|
getEnvelopeReceiver(): Promise<any> {
|
||||||
return this.http.get<any>(this.url);
|
return firstValueFrom(this.http.get<any>(this.url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LocalizationService } from './localization.service';
|
||||||
|
|
||||||
|
describe('LocalizationService', () => {
|
||||||
|
let service: LocalizationService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(LocalizationService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import { Injectable, inject } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable, firstValueFrom } from 'rxjs';
|
||||||
|
import { API_URL } from '../tokens/index';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class LocalizationService {
|
||||||
|
|
||||||
|
private url: string;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
const api_url = inject(API_URL);
|
||||||
|
this.url = `${api_url}/localization`;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLocalizer(): Promise<any> {
|
||||||
|
return firstValueFrom(this.http.get<any>(this.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
using DigitalData.Core.API;
|
||||||
|
using EnvelopeGenerator.Application.Resources;
|
||||||
|
using Microsoft.AspNetCore.Localization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class LocalizationController : ControllerBase
|
||||||
|
{
|
||||||
|
private static readonly Guid L_KEY = Guid.NewGuid();
|
||||||
|
|
||||||
|
private readonly ILogger<LocalizationController> _logger;
|
||||||
|
private readonly IStringLocalizer<Resource> _localizer;
|
||||||
|
private readonly IMemoryCache _cache;
|
||||||
|
public LocalizationController(ILogger<LocalizationController> logger, IStringLocalizer<Resource> localizer, IMemoryCache memoryCache)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_localizer = localizer;
|
||||||
|
_cache = memoryCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAll() => Ok(_cache.GetOrCreate(L_KEY, _ => _localizer.ToDictionary()));
|
||||||
|
|
||||||
|
[HttpGet("lang")]
|
||||||
|
public IActionResult GetLanguage() => Language is null ? NotFound() : Ok(Language);
|
||||||
|
|
||||||
|
[HttpPost("lang")]
|
||||||
|
public IActionResult SetLanguage([FromQuery] string language)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(language))
|
||||||
|
return BadRequest();
|
||||||
|
|
||||||
|
Language = language;
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("lang")]
|
||||||
|
public IActionResult DeleteLanguage()
|
||||||
|
{
|
||||||
|
Language = null;
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string? Language
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var cookieValue = Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(cookieValue))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var culture = CookieRequestCultureProvider.ParseCookieValue(cookieValue)?.Cultures[0];
|
||||||
|
return culture?.Value ?? null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value is null)
|
||||||
|
Response.Cookies.Delete(CookieRequestCultureProvider.DefaultCookieName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var cookieOptions = new CookieOptions()
|
||||||
|
{
|
||||||
|
Expires = DateTimeOffset.UtcNow.AddYears(1),
|
||||||
|
Secure = false,
|
||||||
|
SameSite = SameSiteMode.Strict,
|
||||||
|
HttpOnly = true
|
||||||
|
};
|
||||||
|
|
||||||
|
Response.Cookies.Append(
|
||||||
|
CookieRequestCultureProvider.DefaultCookieName,
|
||||||
|
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(value)),
|
||||||
|
cookieOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.API" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.API" Version="1.0.1" />
|
||||||
<PackageReference Include="DigitalData.Core.Application" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Application" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.DTO" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.DTO" Version="1.0.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Infrastructure" Version="1.0.0" />
|
<PackageReference Include="DigitalData.Core.Infrastructure" Version="1.0.0" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user