quarkiverse / quarkus-renarde

Server-side Web Framework with Qute templating, magic/easier controllers, auth, reverse-routing
Apache License 2.0
73 stars 16 forks source link

Support localized URLs #206

Open geertvanleemputten opened 3 months ago

geertvanleemputten commented 3 months ago

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 commented 3 months ago

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

geertvanleemputten commented 3 months ago

I am glad you asked. ;-)

https://nextjs.org/docs/pages/building-your-application/routing/internationalization

FroMage commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

geertvanleemputten commented 3 months ago

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.