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

Optionally remove unpublished pages from the translated languages, move into untranslated list #1482

Merged
merged 3 commits into from
May 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ protected function processFrontmatter()

/**
* Return an array with the routes of other translated languages
*
* @param bool $onlyPublished only return published translations
*
* @return array the page translated languages
*/
public function translatedLanguages()
public function translatedLanguages($onlyPublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -192,6 +195,10 @@ public function translatedLanguages()
$route = $aPage->slug();
}

if ($onlyPublished && !$aPage->published()) {
continue;
}

$translatedLanguages[$language] = $route;
}
}
Expand All @@ -201,9 +208,12 @@ public function translatedLanguages()

/**
* Return an array listing untranslated languages available
*
* @param bool $includeUnpublished also list unpublished translations
*
* @return array the page untranslated languages
*/
public function untranslatedLanguages()
public function untranslatedLanguages($includeUnpublished = false)
{
$filename = substr($this->name, 0, -(strlen($this->extension())));
$config = Grav::instance()['config'];
Expand All @@ -212,7 +222,13 @@ public function untranslatedLanguages()

foreach ($languages as $language) {
$path = $this->path . DS . $this->folder . DS . $filename . '.' . $language . '.md';
if (!file_exists($path)) {
if (file_exists($path)) {
$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');
if ($includeUnpublished && !$aPage->published()) {
$untranslatedLanguages[] = $language;
}
} else {
$untranslatedLanguages[] = $language;
}
}
Expand Down