diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index ccf8b196219..f5581090d08 100644 --- a/src/app/header/header.component.spec.ts +++ b/src/app/header/header.component.spec.ts @@ -12,6 +12,7 @@ import { MenuService } from '../shared/menu/menu.service'; import { MenuServiceStub } from '../shared/testing/menu-service.stub'; import { HostWindowService } from '../shared/host-window.service'; import { HostWindowServiceStub } from '../shared/testing/host-window-service.stub'; +import { LocaleService } from '../core/locale/locale.service'; let comp: HeaderComponent; let fixture: ComponentFixture; @@ -19,6 +20,11 @@ let fixture: ComponentFixture; describe('HeaderComponent', () => { const menuService = new MenuServiceStub(); + // Mock LocaleService + const localeServiceMock = { + getCurrentLanguageCode: () => 'en' // returns default language code + }; + // waitForAsync beforeEach beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ @@ -29,7 +35,8 @@ describe('HeaderComponent', () => { declarations: [HeaderComponent], providers: [ { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, - { provide: MenuService, useValue: menuService } + { provide: MenuService, useValue: menuService }, + { provide: LocaleService, useValue: localeServiceMock } ], schemas: [NO_ERRORS_SCHEMA] }) diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 5153a19be47..0a847d1b289 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -3,6 +3,7 @@ import { Observable } from 'rxjs'; import { MenuService } from '../shared/menu/menu.service'; import { MenuID } from '../shared/menu/menu-id.model'; import { HostWindowService } from '../shared/host-window.service'; +import { LocaleService } from '../core/locale/locale.service'; /** * Represents the header with the logo and simple navigation @@ -24,6 +25,7 @@ export class HeaderComponent implements OnInit { constructor( protected menuService: MenuService, protected windowService: HostWindowService, + private localeService: LocaleService, ) { } @@ -34,4 +36,41 @@ export class HeaderComponent implements OnInit { public toggleNavbar(): void { this.menuService.toggleMenu(this.menuID); } + + /** + * Returns the current language code from the locale service + * @returns {string} The current language code + */ + getLangCode(): string { + return this.localeService.getCurrentLanguageCode(); + } + + /** + * Returns the current language code only if it's Czech ('cs'), otherwise returns an empty string + * @returns {string} The language code if Czech, empty string otherwise + */ + getLangCodeIfCzech(): string { + return this.localeService.getCurrentLanguageCode() === 'cs' ? this.localeService.getCurrentLanguageCode() : ''; + } + + /** + * Translates English slugs to their Czech equivalents when the current language is Czech + * @param {string} slug - The English slug to translate + * @returns {string} The translated slug if in Czech, the original slug if in English, or empty string if translation not found + */ + translateSlug(slug: string): string { + const currentLang = this.localeService.getCurrentLanguageCode(); + if (currentLang === 'en') { + return slug; + } + + const translations = { + 'partners': 'partneri', + 'integration': 'integrace', + 'partnership': 'partnerstvi', + 'services': 'sluzby' + }; + + return translations[slug] || ''; + } } diff --git a/src/app/item-page/clarin-license-info/clarin-license-info.component.ts b/src/app/item-page/clarin-license-info/clarin-license-info.component.ts index be7be7b3bfc..7b1c3104257 100644 --- a/src/app/item-page/clarin-license-info/clarin-license-info.component.ts +++ b/src/app/item-page/clarin-license-info/clarin-license-info.component.ts @@ -99,7 +99,7 @@ export class ClarinLicenseInfoComponent implements OnInit { } /** - * Check if current english is Czech + * Check if current language is Czech */ isCsLocale() { return this.localeService.getCurrentLanguageCode() === 'cs'; diff --git a/src/themes/dspace/app/header/header.component.html b/src/themes/dspace/app/header/header.component.html index db6ab5ce03e..58b9baf7516 100644 --- a/src/themes/dspace/app/header/header.component.html +++ b/src/themes/dspace/app/header/header.component.html @@ -17,34 +17,34 @@