Files
uiogaming.no/src/components/ui/languageSelector.tsx
T
leanderandClaude Opus 5.5 70ba50c515 Hide decorative flags from screen readers in the language selector
The flags had titles that repeated the button text. Also mark each
language name with its own lang so it's pronounced correctly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:54:18 +01:00

41 lines
1.2 KiB
TypeScript

"use client"
import { GB, NO } from "country-flag-icons/react/3x2"
import { type Locale, useLocale } from "next-intl"
import { usePathname, useRouter } from "@/i18n/navigation"
import * as styles from "./languageSelector.module.css"
const LanguageSelector = () => {
const locale = useLocale()
const router = useRouter()
// Pathname without the locale prefix
const pathname = usePathname()
const changeLocale = (newLocale: Locale) => {
// Read at click time, since useSearchParams() would opt pages out of
// static rendering
const { search, hash } = window.location
router.push(`${pathname}${search}${hash}`, { locale: newLocale })
}
return (
<div className={styles.languageSwitcher}>
{locale === "no" ? (
<button onClick={() => changeLocale("en")} className={styles.button}>
<GB className={styles.flag} aria-hidden="true" />
<span lang="en">English</span>
</button>
) : (
<button onClick={() => changeLocale("no")} className={styles.button}>
<NO className={styles.flag} aria-hidden="true" />
<span lang="no">Norsk</span>
</button>
)}
</div>
)
}
export default LanguageSelector