Routing issues with multi language


#21

I have no knowledge at all regarding AMP pages and I have no plans to fill that whole, I’m afraid.++

Just as before, for pages without URL key, use the regex or just (:any), for pages with URL-key, use different routes.


#22

I was not really thinking that you should do this @texnixe. Understand that you have more than enough on your plate. :wink: But for later ref. This is really simple and Kirby have all the tools for this. It is light weight site format for Google to like you more. All you need is a separate path/URL for the amp page and you repurpose the content with separate template. Also needed in some cases custom Kirby tags for “re-tagging” some of the image and video content. I add the link for anyone that comes after us and want to know more…

Yes, but how?


#23

Your code from earlier in the forum works really well, on how to insert the language code for urls that do not have it, @texnixe :slight_smile: . And the code from @lukasbestle does not. Is there anything that have changed in the last releases?

array(
    'pattern' => '(:any)',
    'action' => function($uri) {
      if ($uri == 'br' or $uri == 'en' or substr( $uri, 0, 2 ) === "br" || substr($uri, 0, 2) == 'en') {
        $site = kirby()->site();
        $page = page('home');
        return $site->visit($page);
      } else {
          $site = kirby()->site();
          $page = page($uri);
          go('br/' . $page);
      }
   }
 ),

How hard is it for this code to also be URL-key aware as well @texnixe?


#24

The pages with URL key, are they known or can they be any pages?


#25

They can be anywhere. The languages is very different from each other.


#26

Is there any ex. I can look at for this to make Omit with the URL-keys intact @texnixe?

:wink:


#27

I was going to look into this some more but haven’t found the time yet.


#28

Great @texnixe. I can keep my it on ice for a little while. :smile: Thank you for following up… You are doing a great job.

I have some odd behaviour even after removing all routes on the home page only. After a little reading here on the forum I understand that is triggered by the automatic language detection.
Do you want me to post it here or open a new tread?


#29

Better open a new. thread, otherwise it all. gets. messed. up just. like my characters on the. keyboard.


#30

Could you let me know which routes you’ve got working now and which not. I have lost track…


#31

Yes, I will just need to test it all. Cause the automatic language detection added a lot of extra mess. I will get back later tonight. Until than have a perfect day @texnixe. :slight_smile:


#32

I have not got around to do the full test. I will get back. I try to make sense of all the issues. So I don´t add more complexity than needed.


#33

I post each set of route separate for a little cleaner communication.

This “fallback route” that you have written a time back was the missing piece of my routes. And it works very very well with two exceptions.

array(
    'pattern' => '(:any)',
    'action' => function($uri) {
      if ($uri == 'br' or $uri == 'en' or substr( $uri, 0, 2 ) === "br" || substr($uri, 0, 2) == 'en') {
        $site = kirby()->site();
        $page = page('home');
        return $site->visit($page);
      } else {
          $site = kirby()->site();
          $page = page($uri);
          go('br/' . $page);
      }
   }
 ),

Issue #1
It does fail if there is a URL-key involved. Gracefully. But it had been nice that it worked.

Issue #2
This is bug somehow. On the home page only. The language menu works and does it´s job and the url change from /br (default) to /en but the content on the page stay in the default language, and do not change.


#34

This code for using the amp.php template works well with one problem.

array(
    'pattern' => '(?:(^[A-Za-z]{2})//?)?articles/(:any)/amp',
    'action'  => function($lang, $article) {
      $lang = $lang ?: 'br'; // the default language
      $page = page('articles/' . $article);
      site()->visit($page, $lang);

      tpl::$data = array_merge(tpl::$data, array(
        'kirby' => kirby(),
        'site'  => site(),
        'pages' => pages(),
        'page'  => page()
      ), $page->templateData());

      return new Response(tpl::load(kirby()->roots()->templates() . DS . 'amp.php'), 'html', 200);
    }
  ),

Issue #1
Fails when there is URL-key in use. And gives this error upon on trying to visit the /amp page when the page have a URL-key.


#35

All the omit rules/routes fails. And also brakes the page starting at the home page. I have tried to manually add the /en and removing the regex and $lang but this just goes to the default error page.

And there is no URL-key support. It gives the default Kirby error page when I make it apply to the blog of mine. But it does shorten the url as expected.

array(
    'pattern' => '(?:(^[A-Za-z]{2})//?)?(:any)',
    'action'  => function($lang,$uid) {
      $lang = $lang ?: 'br';
      $page = page($uid);
  
      // if(!$page) $page = page('articles/' . $uid);
      if(!$page) $page = page('lander/' . $uid);
      if(!$page) $page = page('blog/' . $uid);
      //if(!$page) $page = page('link/' . $uid);
      if(!$page) $page = site()->errorPage();
  
      return site()->visit($page, $lang);
  
    }
  ),
  array(
    'pattern' => '(?:(^[A-Za-z]{2})//?)?lander/(:any)',
    'action'  => function($lang,$uid) {
      $lang = $lang ?: '';
    go($lang.'/'.$uid);
    }
  ),
  array(
    'pattern' => '(?:(^[A-Za-z]{2})//?)?blog/(:any)',
    'action'  => function($lang,$uid) {
        $lang = $lang ?: '';
      go($lang.'/'.$uid);
    }
  ),

#36

Are you using. language code for both. languages now?


#37

As regards the amp route: I get the same error and I have no idea how to solve that. Maybe if you use a content representation instead of the route?


#38

Yes. It makes much easier and do not have any big draw-back for ex. SEO. And if I get the “fallback route” to work it also removes the last issues for myself as well and the setup I have around the website. Like the inbound links that goes to the website. :slight_smile:

Here are my language setup:

c::set('languages', array(
  array(
    'code'    => 'br',
    'name'    => 'Portuguese',
    'default' => true,
    'locale'  => 'pt_BR',
    'url'     => '/br',
  ),
  array(
    'code'    => 'en',
    'name'    => 'English',
    'locale'  => 'en_US',
    'url'     => '/en',
  ),
));

#39

Sorry, but I have no idea of what you ask me here. This AMP code was a hack of several forum posts. So I am not sure how I can reach the same result differently. Can you expand on this?

In the past the default Kirby behaviour was to redirect to the URL-key if the value was not present in the url. But the language code for the language with the URL-key was there. Today it goes strait to the default error page if the URL-key is not present in the url. Is there a way to make that happen again with the routes? If that was the case, would it be possible, to apply this first and than the AMP-route second? Will that solve the problem?


#40

@texnixe will you like to have a direct interaction with my code? I can DM you github access?