Routes > Language scope is ignored?

Hey,

i have a multi-language site (de & en). I need some routing to simplify the urls. But it seems that the language scope is ignored. I want a route just for the german and a route for the english pages.

I also run in the problem, that with these kind of routes the english home page is getting a 404.

Here is a little example of the page structure:

Lang     Panel                          Live
-----    -----                          ----
DE       /                              /                  Startseite (DE)
DE       /gesicht                       /gesicht
DE       /gesicht/gesicht-sub-page      /gesicht-sub-page

EN       /en                            /en                Startseite (EN)
EN       /face                          /face
EN       /face/face-sub-page            /face-sub-page


Here is my current try for the routing. It works only for DE, but not for EN:

[
    'pattern' => '(:any)',
    'language' => 'de',
    'action' => function ($uid) {
        $page = kirby()->page($uid);
        if (!$page) $page = page('gesicht/' . $uid);
        if (!$page) $page = site()->errorPage();
        return site()->visit($page);
    }
],
[
    'pattern' => '(:any)',
    'language' => 'en',
    'action' => function ($uid) {
        $page = kirby()->page($uid);
        if (!$page) $page = page('face/' . $uid);
        if (!$page) $page = site()->errorPage();
        return site()->visit($page);
    }
],

Any help would be appreciated

Thanks – Matthias

See the documentation: Routing | Kirby CMS

@texnixe I already try to figure out by reading the documentation (before I posted to the forum). But to be honest the documentation at this point is not really good to explain how the api works. There are some examples and some minor explanation. That’s it. And as I understand “language scope” it doesn’t work:

If I have no routes at all - all pages are rendered the way Kirby does it out of the box. Fine. If I make a route just with a de-scope, the english pages are affected as well. Why?

As you can see from example I linked to above, you have to pass the language argument to the closure as first argument

    'action' => function ($language, $uid) {

then pass the language code to site()->visit()

Thanks @texnixe. I came up with this solution:

[
  'pattern' => '(:any)',
  'language' => '*',
  'action' => function ($language, $uid) {
      if (page($uid)) {
          return $this->next();
      }
      if ($page = page('gesicht/' . $uid)) {
          return $page;
      }
      if ($page = page('face/' . $uid)) {
          return $page;
      }
      return false;
  }
],

But sadly I wasn’t able to find a working solution based on Removing the parent page slug from the URL from the documentation for multi language sites (using site()->visit()), which I used before adding a second language.