getgrav / grav-plugin-langswitcher

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

Inactive language with trailing slash #29

Closed jimblue closed 2 years ago

jimblue commented 7 years ago

There is problem with the url of the home page for inactive language. A trailing slash is added even if no extension are set in config.

The problem is visible for both langswitcher.hreflang.html.twig and langswitcher.html.twig:

For exemple if English page is active it render:

<link rel="alternate" href="/en" hreflang="en" />
<link rel="alternate" href="/fr" hreflang="fr/" />

and

<ul class="langswitcher">
<li><a class="langswitcher-button" active href="en">English</a></li>
<li><a class="langswitcher-button" href="fr/">Français</a></li>
</ul>

The problem is also visible on the url bar if redirect trailing slash is set to off in config.

jimblue commented 7 years ago

Any update about this?

rhukster commented 7 years ago

Just busy with other things. If you can find a fix, propose a Pull Request and i'll take a look. Cheers.

jimblue commented 7 years ago

@rhukster sure I will 😄 !

gen035 commented 5 years ago

Hey @jimblue I'm having the same issue with a website right now did you find a fix?

elemention commented 5 years ago

Has anyone found a solution?

gen035 commented 5 years ago

@elemention I ended up creating a quick fix in the plugin's template directly:

I added theses lines at line 10 of the langswitcher.html.twig file

{% if langswitcher.page_route == '/' %}
            {% set lang_url = base_lang_url %}
        {% else %}
            {% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
        {% endif %}
jimblue commented 5 years ago

nope @gen035 didn't find a fix

elemention commented 5 years ago

@elemention I ended up creating a quick fix in the plugin's template directly:

I added theses lines at line 10 of the langswitcher.html.twig file

{% if langswitcher.page_route == '/' %}
            {% set lang_url = base_lang_url %}
        {% else %}
            {% set lang_url = base_lang_url ~ langswitcher.page_route ~ page.urlExtension %}
        {% endif %}

work like a charm if include_default_lang: true, many thx @gen035 otherwise if include_default_lang: false, when active now, for example - IT, on link of default language EN, we have link of current active lang IT, and link like - localhost/it - instead - localhost/ maybe i try to found fix later

rhukster commented 2 years ago

Pretty sure this has been fixed for a while.