Grav: Multi-Language Routing not working as documented

Created on 23 Dec 2016  Â·  17Comments  Â·  Source: getgrav/grav

Hello,
probably there's a typo in this part of this document https://learn.getgrav.org/content/multi-language#multi-language-routing, because it says that the Freanch produced url for the given folder structure is http://yoursite.com/animaux/mammiferes/ours while the real produced url is http://yoursite.com/fr/animaux/mammiferes/ours. To me, the first url is preferable, so is there a way to remove the language prefix from other pages than the default one? My system.yaml configuration is

languages:
  translations: true
  include_default_lang: false
  http_accept_language: false
  override_locale: false
  supported:
    - it
    - en
question

Most helpful comment

This is okay compromise if you using one domain if you are using different domains for different languages then we have an issue.
E.g.

consumerOpinion.com/how-to-decide
consumerOpinion.com/fr/how-to-decide or consumerOpinion.com/fr/comment-decider
seems okay so far as we have prefix for different language but when you start using multi domains... ( I reckon most of people use multi domains for different languages )

conceilConso.fr/comment-decider -> this is what I want...
conceilConso.fr/fr/comment-decider -> this is what I am forced to have...

Would be nice to have and options for multi domain setup, if there is a different domain you could instead of prefix use domain name to decide the language.

All 17 comments

As configured, Italian is your default language. Put French first (the default position) and things should work.

@Perlkonig in my real case Italian correspond to French in example, so it is the defaukt one and works as expected. The problem is with English language url http://mysite/en/collection/product which should be http://mysite/collection/product

Sorry for the misunderstanding. The example in the docs uses custom slugs so the language isn't needed. Your config seems fine, but I can't see your page files. If you don't override the routing, then the language portion is necessary. Read the docs you linked to again and you will see the examples. I'm surprised there's not a multi-language example skeleton.

There is a skeleton called "Multilang" that is a basic multi-language example.

I'll try to take a look at this specific question tomorrow.

How odd. Searching with a capital M didn't pull that skeleton up, but lowercase did. Might be my phone ☺

No, it's true, it's a bug in the search on the Grav site

As for the OP issue, it's expected as per https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Service/PageServiceProvider.php#L65-L67

So we should either state this in the docs, or find a way to disable this automated redirect to a lang safe route.

Speaking of lang routing. I experienced an issue while changing languages. With 2 langs enabled (namely EN and PL) I made a page "portfolio". Default lang is EN, folder's name is portfolio, in PL I defined slug as "oferta". When on EN version of the site link on lang switcher for PL points to /pl/portfolio. After clicking it the site changes to /pl/portfolio but the link on lang switcher for PL is now /pl/oferta (which is the correct one). So basically one page has two different URLs.

That is expected. The slug is the route the browser users to reach the page. If you change the slug, you change the URL. The langswitcher actually points to the /pl/portfolio, which is the "rawroute", after it reaches that, grav will redirect to the defined slug-based route.

Redirects like in 301 redirects? Because I don't see any redirecting on mine :(

It's an optional setting in system.yaml:

pages:
    redirect_default_route: true

Closing to due to inactivity

Same issue over here.

I would like to remove language prefixes if I define slug. as I have multiple site setup and dont want to indicate languages in url.

You cannot remove language prefix entirely if the language is not the default language. Grav only loads 1 set of pages for a particular language at a time and therefore doesn't know what custom routes/slugs are set if it doesn't know the language you are in. This is the compromise we made for powerful and flexible language configuration without a performance impact.

This is okay compromise if you using one domain if you are using different domains for different languages then we have an issue.
E.g.

consumerOpinion.com/how-to-decide
consumerOpinion.com/fr/how-to-decide or consumerOpinion.com/fr/comment-decider
seems okay so far as we have prefix for different language but when you start using multi domains... ( I reckon most of people use multi domains for different languages )

conceilConso.fr/comment-decider -> this is what I want...
conceilConso.fr/fr/comment-decider -> this is what I am forced to have...

Would be nice to have and options for multi domain setup, if there is a different domain you could instead of prefix use domain name to decide the language.

+1. It should know the language based on domain, no need to have anything else in the URL.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThinkDevStudios picture ThinkDevStudios  Â·  17Comments

marktaylor46 picture marktaylor46  Â·  26Comments

Sogl picture Sogl  Â·  24Comments

ekumlin picture ekumlin  Â·  37Comments

ulilu picture ulilu  Â·  29Comments