Skip to content

Commit

Permalink
Make the locale picker functional
Browse files Browse the repository at this point in the history
This is limited to supported locales which currently only is 'en-US'.

Refs: #2044
  • Loading branch information
erkannt committed Oct 25, 2024
1 parent 38244b3 commit b31a70d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions assets/locale-picker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
export class LocalePicker extends HTMLElement {
static element = 'locale-picker' as const

constructor() {
super()

this.addEventListener('click', event => {
if (!(event.target instanceof HTMLElement)) {
return
}
const locale = event.target.dataset['locale']
if (locale !== undefined) {
document.cookie = `locale=${locale}`
location.reload()
}
})
}
}

window.customElements.define(LocalePicker.element, LocalePicker)
3 changes: 2 additions & 1 deletion src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ export function page({
<locale-picker>
<ul>
<li><a href="#">English</a></li>
<li><a href="#" data-locale="en-US">English</a></li>
<li><a href="#" data-locale="es-419">Spanish</a></li>
</ul>
</locale-picker>
</div>
Expand Down

0 comments on commit b31a70d

Please sign in to comment.