Next.js Discord

Discord Forum

How to translate nextjs

Unanswered
Yacare Caiman posted this in #help-forum
Open in Discord
Yacare CaimanOP
how to add support for 2 languages in my nextjs app without using /en/something etc
just by a json and automatically detecting language
if it doesnt exist fallback to english

16 Replies

American Crow
You can do it yourself using middleware and there is a basic guide to it here:
https://nextjs.org/docs/pages/building-your-application/routing/internationalization

However if you want to get more sophisticated with it. Think of localized slugs, fallbacks, default time zones and so on you most likely want to use a lib for all the internationalization.
I can recommend next-intl used it in my last project and would use it again. It supports (unstable) static generation and is Next-first by design. https://next-intl-docs.vercel.app/
I recommend using next-intl and if you don’t want to use any language prefix just add localePrefix: “never” to your middleware that you created regarding to the documentation
Yacare CaimanOP
Thanks!
Yacare CaimanOP
i wasnt ready tho...
can i make it without using /en and /de
like
automatically detect the language
without creating 2 links
@Yacare Caiman i wasnt ready tho...
American Crow
from docs
A locale prefix is present in the pathname (e.g. ca.example.com/fr)
A locale is stored in a cookie and is supported on the domain
A locale that the domain supports is matched based on the accept-language header
As a fallback, the defaultLocale of the domain is used

You have the option between different strategies. Please read form docs: https://next-intl-docs.vercel.app/docs/routing/middleware#prefix-based-routing
Yacare CaimanOP
yo, ive made it using /en and /bg
but for some reason google thinks its a copy of the page
and it doesnt index the english version
is there a way to fix it?
but i have no idea how to make a <link rel="canonical" metadata in the app router
nvm