Skip to content

Commit 5f3a909

Browse files
feat: language switcher (#63)
* [dyad] Add language switcher to navigation - wrote 5 file(s) * Add flags to language options in the dropdown for better visibility
1 parent 4a9956b commit 5f3a909

5 files changed

Lines changed: 67 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Intentionally blank */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- Dropdown for Desktop -->
2+
<div *ngIf="displayMode === 'dropdown'" class="relative language-switcher-container">
3+
<button (click)="toggleDropdown()" class="flex items-center text-gray-700 hover:text-indigo-600 focus:outline-none transition-colors duration-200" i18n-title title="Select language">
4+
<i class="ph ph-globe ph-l"></i>
5+
</button>
6+
7+
<div
8+
*ngIf="isDropdownOpen"
9+
class="absolute right-0 mt-2 w-40 bg-white rounded-md shadow-lg z-20"
10+
>
11+
<div class="py-1">
12+
<a href="/" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-indigo-600" (click)="closeDropdown()">
13+
🇬🇧 English
14+
</a>
15+
<a href="/pt" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-indigo-600" (click)="closeDropdown()">
16+
🇧🇷 Português
17+
</a>
18+
</div>
19+
</div>
20+
</div>
21+
22+
<!-- Inline for Mobile -->
23+
<div *ngIf="displayMode === 'inline'" class="w-full text-center py-2">
24+
<div class="flex justify-center items-center space-x-4">
25+
<a href="/" class="text-base font-medium text-gray-700 hover:text-indigo-600">English</a>
26+
<span class="text-gray-300">|</span>
27+
<a href="/pt" class="text-base font-medium text-gray-700 hover:text-indigo-600">Português</a>
28+
</div>
29+
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, HostListener, Input } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@Component({
5+
selector: 'app-language-switcher',
6+
standalone: true,
7+
imports: [CommonModule],
8+
templateUrl: './language-switcher.html',
9+
styleUrl: './language-switcher.css'
10+
})
11+
export class LanguageSwitcher {
12+
@Input() displayMode: 'dropdown' | 'inline' = 'dropdown';
13+
14+
isDropdownOpen = false;
15+
16+
toggleDropdown() {
17+
this.isDropdownOpen = !this.isDropdownOpen;
18+
}
19+
20+
closeDropdown() {
21+
this.isDropdownOpen = false;
22+
}
23+
24+
@HostListener('document:click', ['$event'])
25+
onDocumentClick(event: MouseEvent) {
26+
const target = event.target as HTMLElement;
27+
if (!target.closest('.language-switcher-container')) {
28+
this.closeDropdown();
29+
}
30+
}
31+
}

src/app/component/navigation/navigation.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
</a>
88

99
<!-- Desktop Menu -->
10-
<div class="hidden md:flex space-x-6">
10+
<div class="hidden md:flex items-center space-x-6">
1111
<a href="#services" class="text-gray-700 hover:text-indigo-600 text-lg font-medium transition-colors duration-200" i18n>Services</a>
1212
<a href="#portifolio" class="text-gray-700 hover:text-indigo-600 text-lg font-medium transition-colors duration-200" i18n>Our apps</a>
1313
<a href="#contact" class="text-gray-700 hover:text-indigo-600 text-lg font-medium transition-colors duration-200" i18n>Contact</a>
14+
<app-language-switcher displayMode="dropdown"></app-language-switcher>
1415
</div>
1516

1617
<!-- Hamburger Button -->
@@ -34,6 +35,8 @@
3435
<a href="#services" (click)="closeMenu()" class="block w-full text-center px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:text-indigo-600 hover:bg-gray-50" i18n>Services</a>
3536
<a href="#portifolio" (click)="closeMenu()" class="block w-full text-center px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:text-indigo-600 hover:bg-gray-50" i18n>Our apps</a>
3637
<a href="#contact" (click)="closeMenu()" class="block w-full text-center px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:text-indigo-600 hover:bg-gray-50" i18n>Contact</a>
38+
<div class="border-t border-gray-200 w-full my-2"></div>
39+
<app-language-switcher displayMode="inline"></app-language-switcher>
3740
</div>
3841
</div>
3942
</nav>

src/app/component/navigation/navigation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Component } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3+
import { LanguageSwitcher } from '../language-switcher/language-switcher';
34

45
@Component({
56
selector: 'app-navigation',
67
standalone: true,
7-
imports: [CommonModule],
8+
imports: [CommonModule, LanguageSwitcher],
89
templateUrl: './navigation.html',
910
})
1011
export class Navigation {

0 commit comments

Comments
 (0)