File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 < a href ="#blog " class ="navbar-item "> News</ a >
2424 < a href ="#contact " class ="navbar-item "> Contact</ a >
2525
26+
27+
2628 < div class ="navbar-item ">
2729 < div class ="buttons ">
2830 < a class ="button brand-gradient " href ="#contact ">
3335 </ a >
3436 </ div >
3537 </ div >
38+
39+ < div class ="navbar-item has-dropdown is-hoverable ">
40+ < a class ="navbar-link ">
41+ {{ selectedLanguage.name }}
42+ </ a >
43+
44+ < div class ="navbar-dropdown ">
45+ < a class ="navbar-item "> {{ defaultLanguage.name }}</ a >
46+
47+ @for (translation of availableTranslation; track $index) {
48+ < a class ="navbar-item "> {{ translation.name }}</ a >
49+ }
50+ </ div >
51+ </ div >
3652 </ div >
3753 </ div >
3854</ nav >
Original file line number Diff line number Diff line change 1- import { Component } from '@angular/core' ;
1+ import { AfterViewInit , Component , OnInit } from '@angular/core' ;
2+ declare var window : any ; // To avoid TypeScript errors for window usage
23
34@Component ( {
45 selector : 'app-nav' ,
56 imports : [ ] ,
67 templateUrl : './nav.html' ,
7- styleUrl : './nav.scss'
8+ styleUrl : './nav.scss' ,
89} )
9- export class Nav {
10+ export class Nav implements AfterViewInit {
1011 isActive = false ;
1112
1213 toogleActive ( ) {
1314 this . isActive = ! this . isActive ;
1415 }
16+
17+ defaultLanguage : Language = { name : '🇬🇧 Eng' , baseHref : '' } ;
18+ availableTranslation : Language [ ] = [ { name : '🇧🇷 Por' , baseHref : '/pt/' } ] ;
19+ selectedLanguage : Language = this . defaultLanguage ;
20+
21+ ngAfterViewInit ( ) {
22+ this . selectedLanguage = this . updateSelectedLanguage ( ) ;
23+ }
24+
25+ private updateSelectedLanguage ( ) : Language {
26+ const match = this . availableTranslation . find ( ( lang ) =>
27+ window . location . href . includes ( lang . baseHref )
28+ ) ;
29+ return match || this . defaultLanguage ;
30+ }
31+ }
32+
33+ interface Language {
34+ name : string ;
35+ baseHref : string ;
1536}
File renamed without changes.
You can’t perform that action at this time.
0 commit comments