Skip to content
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

Page::translatedLanguages(): contains slugs or routes #2163

Closed
pamtbaau opened this issue Aug 30, 2018 · 3 comments
Closed

Page::translatedLanguages(): contains slugs or routes #2163

pamtbaau opened this issue Aug 30, 2018 · 3 comments

Comments

@pamtbaau
Copy link
Contributor

pamtbaau commented Aug 30, 2018

The documentation for Page::translatedLanguages() states:

Return an array with the routes of other translated languages

However, the function returns an array with a route when the page has a default route defined, else it returns the slug. Which are quite different imho...

For example, let's assume we have the following folder structure:

.../pages/
     01.my/
        01.example/
           01.page/
  • When the page has a default route defined, it returns the route.
    With the following definition in frontmatter...
    routes:
      default: '/my/example/other-page'
    
    ...it returns the array:
    [ "en" => "/my/example/other-page"]
    
  • When no default route has been defined, it returns the slug for the page:
    [ "en" => "page"]
    

Consequence:
When looping through the results of $page->translatedPages() the different "route" types lead to unexpected results.

$translatedLanguages = $page->translatedLanguages();
foreach ($translatedLanguages as $language => $route) {
    // process $route ;
}
@pamtbaau pamtbaau changed the title Page::translatedPages(): contains slugs or routes Page::translatedLanguages(): contains slugs or routes Aug 30, 2018
@rhukster
Copy link
Member

rhukster commented Sep 6, 2018

Simple fix.

@rhukster rhukster closed this as completed Sep 6, 2018
@pamtbaau
Copy link
Contributor Author

pamtbaau commented Sep 6, 2018

I'm afraid this isn't working...

As far as I can tell, $route = $aPage->route(); always returns null.

Hence Page::translatedLanguages() returns null for each language, unless a route:default is set in frontmatter.

@pamtbaau
Copy link
Contributor Author

pamtbaau commented Sep 28, 2018

@rhukster I'm not sure whether this issue should be closed, but maybe the below behaviour is by design...

When looking at the code for Page::translatedLanguages(), $aPage->route() will always be null, because a page created with ...

$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');

... does not have a parent, and when there is no parent, $aPage->rawRoute() will always be null and $aPage->route() will always be null.

Considering:

  • The slug always has a value, either derived from the folder, or from frontmatter.
  • And, I presume, when a default route is added to frontmatter, it will be in the correct language of the page.

I would therefor, prefer the old behaviour of returning the slug or the default route set in frontmatter. Then the return value will be populated with routes/slugs in the proper language.

I then need to do some handling of the return value, but at least in contains the translated values instead of null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants