Imporved the site
This commit is contained in:
1 parent
888fb6289d
commit
db2bc7ab97
10 files changed
+78
-44
No files matched your search
@@ -1,7 +1,7 @@
|
||||
export class AssetsConstants {
|
||||
|
||||
static readonly ME = '/assets/me.webp';
|
||||
static readonly LOGO = '/assets/favicon.ico';
|
||||
static readonly LOGO = '/assets/logos/logo-wolf.png';
|
||||
static readonly FLAG_DE = '/assets/flags/de.svg';
|
||||
static readonly FLAG_EN = '/assets/flags/gb.svg';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<mat-toolbar class="flex! items-center! p-[clamp(0.5rem,1vw,1rem)]! backdrop-blur-sm! backdrop-saturate-[1.1]! bg-white/80! dark:bg-[#313131]/80! border-b! border-black/8!" color="primary" (keydown)="onKeydown($event)">
|
||||
<a class="flex items-center gap-[clamp(0.4rem,1vw,0.6rem)] text-inherit no-underline" routerLink="/">
|
||||
<img class="w-[clamp(36px,10vw,48px)] h-[clamp(36px,10vw,48px)] rounded-full" src="{{AssetsConstants.LOGO}}" alt="" aria-hidden="true" draggable="false"
|
||||
<img class="w-[clamp(36px,10vw,48px)] h-auto rounded-full" src="{{AssetsConstants.LOGO}}" width="117" height="128" alt="" aria-hidden="true" draggable="false"
|
||||
oncontextmenu="return false;">
|
||||
<span class="font-semibold tracking-[0.2px] text-[clamp(1rem,3vw,1.2rem)]">{{ 'APP.TITLE' | translate }}</span>
|
||||
</a>
|
||||
|
||||
@@ -40,4 +40,15 @@ describe('LanguageService', () => {
|
||||
expect(translateSpy.use).toHaveBeenCalledWith('de');
|
||||
expect(localStorage.getItem(LocalStoreConstants.LANGUAGE_KEY)).toBe('de');
|
||||
});
|
||||
|
||||
it('marks the document with the active language so screen readers switch voice', () => {
|
||||
localStorage.setItem(LocalStoreConstants.LANGUAGE_KEY, 'en');
|
||||
const service = createService();
|
||||
|
||||
expect(document.documentElement.lang).toBe('en');
|
||||
|
||||
service.use('de');
|
||||
|
||||
expect(document.documentElement.lang).toBe('de');
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Injectable, inject, signal } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {LocalStoreConstants} from '../constants/LocalStoreConstants';
|
||||
|
||||
@@ -7,20 +8,32 @@ type Lang = 'de' | 'en';
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LanguageService {
|
||||
private readonly translate = inject(TranslateService);
|
||||
private readonly document = inject(DOCUMENT);
|
||||
readonly lang = signal<Lang>(this.getInitial());
|
||||
|
||||
constructor() {
|
||||
// translate service lang and fallback are already configured via provideTranslateService in app.config
|
||||
// just ensure the stored preference is active on startup
|
||||
this.translate.use(this.lang());
|
||||
this.markDocumentLanguage(this.lang());
|
||||
}
|
||||
|
||||
use(l: Lang) {
|
||||
this.lang.set(l);
|
||||
this.translate.use(l);
|
||||
this.markDocumentLanguage(l);
|
||||
try { localStorage.setItem(LocalStoreConstants.LANGUAGE_KEY, l); } catch (e) { void e; }
|
||||
}
|
||||
|
||||
/**
|
||||
* index.html ships a static lang="en". Without this the document keeps
|
||||
* claiming English after a switch, so a screen reader reads the German
|
||||
* content with an English voice.
|
||||
*/
|
||||
private markDocumentLanguage(l: Lang): void {
|
||||
this.document.documentElement.lang = l;
|
||||
}
|
||||
|
||||
private getInitial(): Lang {
|
||||
try {
|
||||
const stored = localStorage.getItem(LocalStoreConstants.LANGUAGE_KEY) as Lang | null;
|
||||
|
||||
Reference in new issue
Block a user