v2-hub icon indicating copy to clipboard operation
v2-hub copied to clipboard

Language Switcher Links with Subdomain not working correctly

Open RafaelKr opened this issue 4 years ago • 0 comments

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:

  • https://www.example.de/
  • https://en.example.de/

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:

  • http://example.test/
  • http://en.example.test/

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):

  • Statamic Version: 2.11.19
  • Fresh Install or Upgrade: Upgrade
  • OS: Linux Mint 19.2 Tina (base: Ubuntu 18.04 bionic)
  • Browser: Firefox 73.0.1 (64-bit)
  • Web Server: Valet Linux (https://cpriego.github.io/valet-linux/)
  • PHP Version: 7.3
  • Addons installed: Many, but if this info should be required I can provide the full list.

RafaelKr avatar Feb 29 '20 19:02 RafaelKr