Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support localized URLs #206

Open
geertvanleemputten opened this issue Apr 3, 2024 · 9 comments
Open

Support localized URLs #206

geertvanleemputten opened this issue Apr 3, 2024 · 9 comments

Comments

@geertvanleemputten
Copy link

Support localized URLs for SEO purposes, eg:

/some-url (en) [default locale]
/nl/some-url (nl)

Similar to what all JS frameworks out there support.

@FroMage
Copy link
Contributor

FroMage commented Apr 3, 2024

Do you have pointers where this is documented for those JS frameworks?

@geertvanleemputten
Copy link
Author

@FroMage
Copy link
Contributor

FroMage commented Apr 3, 2024

OK thanks.

It's not entirely clear to me how it works, because they claim they redirect to a prefixed URI, or a custom domain, so that the selected locale is apparent.

So, suppose I go to /help with a FR locale in my browser, it will redirect me to /fr/help and I'll get the French version.

Now what happens if I go to /nl/help? Does it give me the NL page, or does it detect that it's the wrong locale and move me back to /fr/help?

That would defeat indexing if the crawler is set to prefer en: it would never be able to crawl the other locale's pages.

Also, I'm not entirely sure how to implement this, given that it also ties in to reverse routing.

A bit more thinking is required.

@geertvanleemputten
Copy link
Author

It does not use the browser language at all. Using a language selector would switch the URL and language, but the idea is that the (google) indexer sends you to the correct URL because you are searching in a specific language.

So this would be a complete alternative to how the localization currently works.

@FroMage
Copy link
Contributor

FroMage commented Apr 3, 2024

I don't think that's accurate:

In https://nextjs.org/docs/pages/building-your-application/routing/internationalization#automatic-locale-detection

When a user visits the application root (generally /), Next.js will try to automatically detect which locale the user prefers based on the Accept-Language header and the current domain.

In https://nextjs.org/docs/pages/building-your-application/routing/internationalization#leveraging-the-next_locale-cookie:

Next.js supports overriding the accept-language header with a NEXT_LOCALE=the-locale cookie. This cookie can be set using a language switcher and then when a user comes back to the site it will leverage the locale specified in the cookie when redirecting from / to the correct locale location.

@geertvanleemputten
Copy link
Author

Ok, I see, but only the root.

That does make sense. I used it previously in an ecommerce project and only the product details pages were of importance to the indexer. So it wouldn't cause an issue for SEO in that case.

Although it would be better if it didn't redirect the root for indexers though.

I did use static generation for the homepage, so im not sure if that still applies in that case.

@FroMage
Copy link
Contributor

FroMage commented Apr 3, 2024

Interesting that Google says its bot doesn't have any Accept-Language header, and advises against automatic redirection: https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites

Apparently, it advises pages to list their localised versions either via link@hreflang elements in <head>, or HTTP headers (better in the case of PDF) or sitemaps: https://developers.google.com/search/docs/specialty/international/localized-versions

@FroMage
Copy link
Contributor

FroMage commented Apr 3, 2024

Makes me wonder if we should have a DEV UI or Quarkus CLI command to generate a sitemap.

@geertvanleemputten
Copy link
Author

I did add the alternative versions in the header on that project if I remember correctly. But I had to do it separately. There was no automatic nextjs support for it.

Sitemap generation could be interesting, but there are also some caveats here that I had to learn the hard way. You can add 50k entries to a sitemap, but its better to split them up in sitemaps of 1k or google will pretty much ignore your sitemap altogether. I had 80k URLs at one point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants