New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple locales: {{ locale:url }} returns the wrong URLs if relative URLs are defined in system.yaml #2044

Closed
ASochat opened this Issue Jul 3, 2018 · 13 comments

Comments

Projects
None yet
7 participants
@ASochat

ASochat commented Jul 3, 2018

Describe the bug

I have two locales on my website: EN (default) and FR. In my system.yaml file, I defined relative URL for each one. When updating from statamic 2.8.12 to 2.9.0, {{ locales }} {{ url }} {{ /locales }} now inserts the segment corresponding to the first $locale in the URL. Example for the page foo.dev/en/stuff, it returns:

foo.dev/en/stuff
foo.dev/en/fr/chose

To Reproduce
Steps to reproduce the behavior:

  1. Change your URLs to relative ones in system.yamlfile
  2. Downgrade to 2.8.12 and check if the code above works
  3. Upgrade to 2.9.0 and see it's not working

Expected behavior
The URLs should match the real ones, without

foo.dev/en/stuff
foo.dev/fr/chose

Environment details (please complete the following information):

  • Statamic Version [2.9.0]
  • Browser: [chrome]
  • Web Server: [ Nginx]
  • PHP Version: [eg. 7.2]

Additional context
I think it comes from the following FIX of 2.9.0 update :

"URL::makeAbsolute() now uses the URL defined in system.locales when absolute. When relative, it just gets a bit smarter. #1882 "

Here is what's in my system.yaml file:

locales:
  en:
    full: en_EN
    name: English
    url: /en/
  fr:
    full: fr_FR
    name: French
    url: /fr/

If I set absolute URLs (like https://foo.com) it works fine, it starts returning errors only with relative URLs.

A workaround is to change the absolute URLs depending on the environments, though I'd like to work with relative URLs on my local machine.

@iljapanic

This comment has been minimized.

iljapanic commented Jul 3, 2018

I was having the same issue with locales on my site.

Thanks for the tip @ASochat. Changing the relative URLs to absolute ones in my system.yaml fixed it.

However, now I have to maintain separate config files for each environment. It would be great if locales worked with relative URLs like they did before the 2.9.0 update.

@1stevengrant

This comment has been minimized.

1stevengrant commented Jul 3, 2018

@iljapanic why not move that into environment variables in that case?

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Jul 3, 2018

In statamic/core/Data/Content/Content.php try changing line 167 to

return URL::makeAbsolute($this->uri(), $this->locale());
@manogi

This comment has been minimized.

manogi commented Jul 12, 2018

I have the same problem (2.9.8), and when I follow @jasonvarga 's advice the locale in all three links (i have three locales) just stays the the current locale - so that does not work for me?
My fix for now:

in my .env file I have:

SITE_ROOT=https://mydomain.test

and in systems.yaml:

  de:
    name: Deutsch
    full: deu
    url: {env:SITE_ROOT}/
  en:
    name: English
    full: eng
    url: {env:SITE_ROOT}/en/
  fi:
    name: Finnish
    full: fin
    url: {env:SITE_ROOT}/fi/
@manogi

This comment has been minimized.

manogi commented Jul 19, 2018

This now (version 2.10.1) does not seem to work at all anymore. Not with relative paths (/fi/), Not with absolute paths (https://mydomain.test/fi/). In my {{ locales }} ... {{ /locales }} loop url just puts out the current url - period.

@manogi

This comment has been minimized.

manogi commented Jul 19, 2018

To clarify: I tried the different url schemes (relative, absolute) in my systems.yaml, to no effect.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Jul 20, 2018

Use {{ permalink }}

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Jul 23, 2018

@manogi Try this instead

image

@manogi

This comment has been minimized.

manogi commented Jul 27, 2018

@jasonvarga Thanks - this did the trick for me.
Sorry for replying so late, was on vacation.
Will this be implemented in 2.10.3?

I also don't need the {env:SITE_ROOT} anymore, relative urls work now.

@manogi

This comment has been minimized.

manogi commented Jul 27, 2018

Side question - do you know the reason why I need to to the nginx rewrites you mention here on a forge server, but not in my Laravel Valet surroundings?

@peda

This comment has been minimized.

peda commented Jul 31, 2018

@jasonvarga when can we expect this fix to be released? visit url does not work, live preview does not work, and many other things are failing too because of this issue ...

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Jul 31, 2018

@peda Soon! Sorry about the delay. We were away at a conference last week and it was difficult to find a reliable internet connection. You can apply this manually for now until the next version is released.

@manogi Yes, this will be in 2.10.3. Also, you don't need the rewrites on Valet because the Statamic driver includes some handling for this out of the box.

@jasonvarga jasonvarga reopened this Jul 31, 2018

@manogi

This comment has been minimized.

manogi commented Jul 31, 2018

@jason thank you for this info!

@jasonvarga jasonvarga closed this Aug 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment