Unverified Commit 4e794815 authored by Pavel Mineev's avatar Pavel Mineev Committed by GitHub

(examples/with-i18n-next-intl): fixes warning (#25928)

### Documentation / Examples

Fixed one of the items from #25854

- Fixes warning from `next-intl`
- Hides locale selector in case if no other location
- Fixes path `next/router` import 
- Removes unused variable

---

- [x] Add the StackBlitz button in README.md
- [x] Make sure the linting passes

[Live demo on StackBlitz](https://stackblitz.com/github/akellbl4/next.js/tree/fix/example-with-i18n-next-intl-missing-other/examples/with-i18n-next-intl)
parent 19804636
import { useTranslations } from 'next-intl'
import { useRouter } from 'next/dist/client/router'
import { useRouter } from 'next/router'
import Link from 'next/link'
export default function Navigation() {
const t = useTranslations('Navigation')
const { locale, locales, route } = useRouter()
const otherLocale = locales?.find((cur) => cur !== locale)
......@@ -18,9 +17,11 @@ export default function Navigation() {
<a>{t('about')}</a>
</Link>
</div>
{otherLocale && (
<Link href={route} locale={otherLocale}>
<a>{t('switchLocale', { locale: otherLocale })}</a>
</Link>
)}
</div>
)
}
......@@ -2,6 +2,6 @@
"Navigation": {
"index": "Start",
"about": "Über",
"switchLocale": "Zu {locale, select, de {Deutsch} en {Englisch}} wechseln"
"switchLocale": "Zu {locale, select, de {Deutsch} en {Englisch} other {}} wechseln"
}
}
......@@ -2,6 +2,6 @@
"Navigation": {
"index": "Home",
"about": "About",
"switchLocale": "Switch to {locale, select, de {German} en {English}}"
"switchLocale": "Switch to {locale, select, de {German} en {English} other {}}"
}
}
import { NextIntlProvider } from 'next-intl'
export default function App({ Component, messages, pageProps }) {
export default function App({ Component, pageProps }) {
return (
<NextIntlProvider
// To achieve consistent date, time and number formatting
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment