statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Language Switcher Links with Subdomain not working correctly #2503

Open RafaelKr opened 4 years ago

RafaelKr commented 4 years ago

Describe the bug I want to run my Statamic 2 page with two different languages (de_DE, en_US). Basically I followed the guide in the docs https://docs.statamic.com/localization

I decided to use a subdomain, so the URLs look like this:

My locales config in system.yaml:

locales:
  de:
    full: de_DE
    name: Deutsch
    url: '{env:LOCALE_DOMAIN_DE}'
  en:
    full: en_GB
    name: English
    url: '{env:LOCALE_DOMAIN_EN}'

Locally I'm using Valet (Linux) and to make it work I also had to symlink the folders assets, site and img (image_manipulation_cached_path for glide) into the en direcory.

Also locally my URLs are like these:

Until here everything works fine.

I now implemented a language switcher that looks like this: image

{{locales}}
    <div><a class="ml-2 pb-1{{if locale_full == locale:full}} border-b{{/if}}" href="{{ url }}">{{ locale:key | upper }}</a></div>
    {{ if !last }}
    <div class="ml-2">|</div>
    {{/if}}
{{/locales}}

The problem is, that both links (DE and EN) always link to the de locale on whatever page or locale I currently am. Example: http://example.test/my/sub/path => http://example.test/my/sub/path

For testing purposes I temporarily changed to a path based locale (/en/) and that was working correctly. Example: Example: http://example.test/my/sub/path => http://example.test/en/my/sub/path

Expected behavior I want the EN link pointing to the current page but with the URL for the locale defined in system.yaml. Example: http://example.test/my/sub/path => http://en.example.test/my/sub/path

Environment details (please complete the following information):