getgrav / grav-plugin-langswitcher

Grav LangSwitcher Plugin
https://getgrav.org
MIT License
28 stars 26 forks source link

hreflang url does not works properly #30

Closed funmaking closed 7 years ago

funmaking commented 7 years ago

Hello guys

I have a problem with the langswitcher plugin. The website has 2 languages: en and es

The main language is defined the English language. All pages are translated (titles, slugs, etc).

When I switch from the es language to en main language the urls of hreflang works correclty. But when I am in the main language (en) and switch to secondary language (es) the metadata of the page translated is not working.

An example:

In a url with url "/en/princing" I switch to spanish version translated like "es/precios" I see in the html code generated:

<link rel="alternate" hreflang="en" href="/en/pricing" />
<link rel="alternate" hreflang="es" href="/es/pricing" />

Nevertheless, if I go to Spanish page (secondary language in Grav) and the switcher is working ok:

<link rel="alternate" hreflang="en" href="/en/pricing" />
<link rel="alternate" hreflang="es" href="/es/precios" />

I.e. the "es" page name translation is not included

I don't know if it's a bug or a problem with my configuration but I think all is configured ok.

Thank you

rhukster commented 7 years ago

This is actually correct output because there is a limitation in Grav where only the current language is loaded at any time, and the raw route must be used to switch to another language. See here for more details: https://github.com/getgrav/grav-plugin-langswitcher/issues/2

Basically when in English, the route for the page in english is /en/pricing, and the rawroute for Spanish is /es/pricing

When in spanish the route for the pages is /es/precios but the rawroute for the english is /en/pricing because it's the default language.

You can however, ensure you end up on the correct page by enabling redirect_default_route - https://github.com/getgrav/grav-plugin-langswitcher/issues/16#issuecomment-271570447

funmaking commented 7 years ago

No, that's not fix the issue. I already had it configured before opening the ticket... I will add the href metadata by hand. Thank you.

rauwebieten commented 7 years ago

This might be a problem, some search engines do not allow redirects apparently: see http://www.johnfdoherty.com/google-sitemaps-ask-for-clean-urls/