I can't get pages in a specific language

Hi everyone,

I have a problem getting children of a page in a specific language. I asked (link -> Remove parent page name in subpage url)
few months ago to remove parent page in subpage url. Thats run correctly but the problem is that my page is multilanguage and when I’m going to find the subpages of my page allways get default language pages and kirby can’t find the page:

$categories = page('blog')->children()->pluck('uri', ','); //<-- here gets children of default language
    $i = 0;

    while($i < count($categories)) {
      if($page = page($categories[$i].'/'.$uid)) {
        return site()->visit($page);
      }
         $i++;
    }

I’ve tried using ->content(‘language code’) and creating a custom filter (link -> Filter child pages by available translations) but I can’t solve it.

Some ideas? :slight_smile: thanks!

Have you tried this: https://k2.getkirby.com/docs/cookbook/multilanguage-secrets#filtering-content-by-language

Nothing… The page goes blank

Is the above code from a route?

Yes is a route but that’s an example. This is my code:

array(
        'pattern' => 'en/our-news/(:any)',
        'action'  => function($uid) {

            if($page = page('en/our-news/'.$uid)) {
                go($page->parent());
            } else {

                $categories = page('nuestras-noticias')->children()->pluck('uri' ',');
                $i = 0;

                foreach($categories as $category){
                    echo $category . '<br>';
                }

                while($i < count($categories)) {
                    if($page = page($categories[$i].'/'.$uid)) {
                        echo $categories[$i];
                        echo $uid;
                        return site()->visit($page, 'en');
                    }

                    $i++;
                }
            }
            return false;
        }
    ),

I can’t look into this now, will try tonight.

What I do seem to understand is that you are using URL-Keys for each language, right?

Yes, I’m using it foreach one

You are using site()->visit($page, 'en');. But I guess you would need to call it with the language code of the language that you want, not hardcoded en.

That route only addresses the URLs starting with en anyway?

Yes, I have that route only for ‘en’ routes. My page is in Spanish (default language) and when y search the children of the page ‘nuestras-noticias’ the method gets Spanish children, not English children so in the while It isn’t being found the page.

Yes, this route I only use for ‘en’ routes

I’ve tried to print the children in a template and there the values ​​change depending on the language. I don’t understand why with the same code, in config file doesn’t run same as in a template. Does this help you?

I have also put page('our-news') (The name of the page of the English version) instead of page('nuestras-noticias') but it does not work either.

Sorry, I haven’t had time to dive into this yet.

Could you send me your project as a zip for testing, I don’t have the time to recreate such a setup at the moment. Then I can look into it over the weekend.