Skip to content

Commit f7b60b5

Browse files
committed
fix: language switcher design
1 parent 7e1d4cb commit f7b60b5

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
11
---
2-
import { languages } from '../i18n/ui';
32
import { base } from "astro:config/client"
43
4+
const languages = Object.keys(import.meta.glob('../pages/*.astro')).map(p=>p.split("/").at(-1).replace(".astro", "")).sort();
55
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, "");
6+
const currentLang = pathname.split("/")[1];
67
---
7-
<ul class="language-picker">
8-
{Object.entries(languages).sort((a, b) => a < b ? 0 : -1).map(([lang, label]) => (
9-
<li class:list= {[{ active: pathname.startsWith(`/${label}`) }]} >
10-
<a href={`${base}/${lang}/`}>{label}</a>
11-
</li>
8+
<div class="language-switcher">
9+
{languages.map((lang, i) => (
10+
<>
11+
<a href={`${base}/${lang}/`} class:list={{active: lang === currentLang}}>
12+
{lang.toUpperCase()}
13+
</a>
14+
{i < languages.length - 1 && <span class="separator">/</span>}
15+
</>
1216
))}
13-
</ul>
17+
</div>
1418

1519
<style>
16-
ul {
17-
list-style: none;
18-
padding: 0;
19-
margin: 0;
20-
display: flex;
21-
justify-content: flex-end;
22-
margin-right: 1rem;
23-
24-
a {
25-
text-decoration: none;
26-
}
20+
.language-switcher {
21+
position: absolute;
22+
top: 1rem;
23+
right: 1rem;
24+
font-size: 1.5rem;
25+
font-weight: 500;
26+
}
2727

28+
.language-switcher a {
29+
color: rgba(255, 255, 255, 0.7);
30+
text-decoration: none;
31+
transition: color 0.2s ease;
2832
}
2933

30-
li:first-child::after {
31-
content: '/';
32-
display: 'inline block'
33-
margin: 0 8px;
34-
color: #333;
34+
.language-switcher a:hover {
35+
color: #ffffff;
36+
text-decoration: underline;
37+
}
3538

39+
.language-switcher .separator {
40+
color: rgba(255, 255, 255, 0.5);
41+
margin: 0 0.3rem;
3642
}
3743

38-
li.active > a {
39-
font-weight: bold;
40-
text-decoration: underline;
44+
/* Active language style */
45+
.language-switcher a.active {
46+
color: #ffffff;
47+
font-weight: 600;
4148
}
4249
</style>

2025/src/i18n/ui.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)