diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index a3fc3dc5e..c177a6a84 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -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']; @@ -192,6 +195,10 @@ public function translatedLanguages() $route = $aPage->slug(); } + if ($onlyPublished && !$aPage->published()) { + continue; + } + $translatedLanguages[$language] = $route; } } @@ -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']; @@ -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; } }