mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 12:26:48 +02:00
Remove unpublished pages from the translated languages, move into untranslated list (#1482)
* Remove unpublished pages from the translated languages, move into untranslated list Refs https://github.com/getgrav/grav-plugin-sitemap/issues/43 * Add missing part * Add flags to avoid breaking changes
This commit is contained in:
@@ -172,9 +172,12 @@ class Page
|
||||
|
||||
/**
|
||||
* 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 @@ class Page
|
||||
$route = $aPage->slug();
|
||||
}
|
||||
|
||||
if ($onlyPublished && !$aPage->published()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$translatedLanguages[$language] = $route;
|
||||
}
|
||||
}
|
||||
@@ -201,9 +208,12 @@ class Page
|
||||
|
||||
/**
|
||||
* 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 @@ class Page
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user