Skip to content

Commit 7a5b124

Browse files
committed
Language switcher re-styled
1 parent 7a65e59 commit 7a5b124

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

apps/play/src/components/Nav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function Nav() {
4141
navigate(`/search?q=${searchInput}`);
4242
}
4343
}}/>
44-
<LanguageSwitcher className="mx-1 p-2 border-round"/>
44+
<LanguageSwitcher className="mx-1"/>
4545
</div>
4646
)}
4747
style={{

apps/web/src/components/Nav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function Nav() {
5454
start={
5555
<img alt="logo" src="/logo.png" height={"40"} className="mx-1" />
5656
}
57-
end={<LanguageSwitcher className="p-2 border-round" />}
57+
end={<LanguageSwitcher className="mr-2" />}
5858
style={{
5959
borderRadius: isMobile ? 0 : "5px",
6060
borderColor: "#1E1E1E",

packages/i18n/LanguageSwitcher.jsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
import React from 'react';
22
import {useTranslation} from 'react-i18next';
3+
import {Dropdown} from 'primereact/dropdown';
34
import {SUPPORTED_LANGUAGES} from './languages';
45

5-
// Dependency-free language picker (plain <select>) so the shared package stays
6-
// light. Apps pass className/style to match their own chrome.
6+
// Language picker built on primereact's Dropdown so it inherits the site theme
7+
// (both apps already ship primereact). A leading globe icon marks it as the
8+
// language control. Apps pass className/style to fit their own chrome.
79
export function LanguageSwitcher({className, style}) {
810
const {i18n, t} = useTranslation();
911
const active = (i18n.resolvedLanguage || i18n.language || 'en').split('-')[0];
1012
const value = SUPPORTED_LANGUAGES.some((l) => l.code === active) ? active : 'en';
1113

14+
const selectedTemplate = (option) => {
15+
const label =
16+
option?.label ??
17+
SUPPORTED_LANGUAGES.find((l) => l.code === value)?.label ??
18+
'';
19+
return (
20+
<span className="flex align-items-center gap-2">
21+
<i className="pi pi-globe" />
22+
<span>{label}</span>
23+
</span>
24+
);
25+
};
26+
1227
return (
13-
<select
28+
<Dropdown
1429
aria-label={t('language')}
1530
className={className}
16-
style={style}
31+
style={{width: '11rem', ...style}}
1732
value={value}
18-
onChange={(e) => i18n.changeLanguage(e.target.value)}
19-
>
20-
{SUPPORTED_LANGUAGES.map((l) => (
21-
<option key={l.code} value={l.code}>{l.label}</option>
22-
))}
23-
</select>
33+
options={SUPPORTED_LANGUAGES}
34+
optionLabel="label"
35+
optionValue="code"
36+
scrollHeight="500px"
37+
onChange={(e) => i18n.changeLanguage(e.value)}
38+
valueTemplate={selectedTemplate}
39+
pt={{
40+
input: {className: 'p-2'},
41+
trigger: {style: {width: '2rem'}},
42+
}}
43+
/>
2444
);
2545
}

packages/i18n/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"react-i18next": "^15.4.0"
1111
},
1212
"peerDependencies": {
13+
"primereact": ">=9",
1314
"react": ">=18"
1415
}
1516
}

0 commit comments

Comments
 (0)