Ensure compatibility with "translation" plugin

cf. https://www.dokuwiki.org/plugin:translation
This commit is contained in:
vv221 2020-04-03 22:13:43 +02:00
parent e79910dd07
commit e137f57890
2 changed files with 22 additions and 16 deletions

View file

@ -27,10 +27,16 @@ class MenuItem extends AbstractItem {
protected function setTargetFromType() : void {
global $INFO;
global $plugin_controller;
$language = null;
// If one of the "translate" or "translation" plugins is activated, get the language code for the current page
if ( ! $plugin_controller->isdisabled('translate') ) {
// If the "translate" plugin is activated, the language code should stay the top-level namespace
$translate_plugin =& $plugin_controller->load('helper', 'translate');
$language = $translate_plugin->getPageLanguage();
} elseif ( ! $plugin_controller->isdisabled('translation') ) {
$translation_plugin =& $plugin_controller->load('helper', 'translation');
$language = $translation_plugin->getLangPart($INFO['id']);
}
// If the top level namespace is a language one, the children namespace should be inserted inside it
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
$this->id = preg_replace(
"/^$language:/",
@ -40,9 +46,6 @@ class MenuItem extends AbstractItem {
} else {
$this->id = $this->type.':'.$INFO['id'];
}
} else {
$this->id = $this->type.':'.$INFO['id'];
}
$this->params = [];
}
}

View file

@ -81,17 +81,20 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
protected function getTopLevelNamespace() : ?string {
global $INFO;
global $plugin_controller;
$language = null;
// If one of the "translate" or "translation" plugins is activated, get the language code for the current page
if ( ! $plugin_controller->isdisabled('translate') ) {
// Skip top-level namespace added by "translate" plugin
$translate_plugin =& $plugin_controller->load('helper', 'translate');
$language = $translate_plugin->getPageLanguage();
} elseif ( ! $plugin_controller->isdisabled('translation') ) {
$translation_plugin =& $plugin_controller->load('helper', 'translation');
$language = $translation_plugin->getLangPart($INFO['id']);
}
// Skip top-level language namespace if one is in use
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
return explode(':', $INFO['namespace'])[1];
} else {
return explode(':', $INFO['namespace'])[0];
}
} else {
return explode(':', $INFO['namespace'])[0];
}
}
}