From 305a3b16c598a98fc7378de3c2ad271e7813de58 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Jun 2016 16:10:53 +0200 Subject: [translation] Make menu categories a global section instead of a hook in main --- modules-available/translation/page.inc.php | 68 +++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'modules-available/translation/page.inc.php') diff --git a/modules-available/translation/page.inc.php b/modules-available/translation/page.inc.php index 5b2d24e1..74cf27a8 100644 --- a/modules-available/translation/page.inc.php +++ b/modules-available/translation/page.inc.php @@ -42,7 +42,7 @@ class Page_Translation extends Page public function __construct() { - $this->builtInSections = array('template', 'messages', 'module', 'custom'); + $this->builtInSections = array('template', 'messages', 'module', 'menucategory', 'custom'); } private function isValidSection($section) @@ -167,6 +167,13 @@ class Page_Translation extends Page return; } + // Menu Category + if ($this->section === 'menucategory') { + $this->ensureValidDestLanguage(); + $this->showMenuCategoryEdit(); + return; + } + // Custom if ($this->section === 'custom') { $this->ensureValidDestLanguage(); @@ -174,7 +181,7 @@ class Page_Translation extends Page return; } - $this->redirect(); + $this->redirect(1); } private function showListOfModules() @@ -212,6 +219,8 @@ class Page_Translation extends Page $this->showModuleMessages(); // Other/hardcoded strings $this->showModuleStrings(); + // Menu categories + $this->showModuleMenuCategories(); // Module specific $this->showModuleCustom(); Render::closeTag('div'); @@ -285,6 +294,23 @@ class Page_Translation extends Page } Render::addTemplate('string-list', $data); } + + private function showModuleMenuCategories() + { + $moduleTags = $this->loadUsedMenuCategories(); + $data = array('module' => $this->module->getIdentifier()); + $data['tagcount'] = count($moduleTags); + foreach (Dictionary::getLanguages(true) as $lang) { + list($missing, $unused) = $this->getModuleTranslationStatus($lang['cc'], 'menucategory', true, $moduleTags); + $data['langs'][] = array( + 'cc' => $lang['cc'], + 'name' => $lang['name'], + 'missing' => $missing, + 'unused' => $unused + ); + } + Render::addTemplate('menu-category-list', $data); + } private function showModuleCustom() { @@ -352,6 +378,17 @@ class Page_Translation extends Page )); } + private function showMenuCategoryEdit() + { + Render::addTemplate('edit', array( + 'destlang' => $this->destLang, + 'language' => Dictionary::getLanguageName($this->destLang), + 'tags' => $this->loadMenuCategoryEditArray(), + 'module' => $this->module->getIdentifier(), + 'section' => $this->section + )); + } + private function showCustomEdit() { Render::addTemplate('edit', array( @@ -453,6 +490,23 @@ class Page_Translation extends Page } return $tags; } + + private function loadUsedMenuCategories($module = false) + { + if ($module === false) { + $module = $this->module; + } + $skip = strlen($module->getIdentifier()) + 1; + $match = $module->getIdentifier() . '.'; + $want = array(); + foreach (Module::getAll() as $module) { + $cat = $module->getCategory(); + if (is_string($cat) && substr($cat, 0, $skip) === $match) { + $want[substr($cat, $skip)] = true; + } + } + return $want; + } private function loadUsedCustomTags($subsection) { @@ -657,6 +711,13 @@ class Page_Translation extends Page $table = $this->buildTranslationTable('module', array_keys($tags), true); return $table; } + + private function loadMenuCategoryEditArray() + { + $tags = $this->loadUsedMenuCategories(); + $table = $this->buildTranslationTable('categories', array_keys($tags), true); + return $table; + } /** * Get array to pass to edit page with all the message ids. @@ -865,6 +926,9 @@ class Page_Translation extends Page if ($this->section === 'module') { return $prefix . '/module.json'; } + if ($this->section === 'menucategory') { + return $prefix . '/categories.json'; + } // Custom submodule if ($this->section === 'custom') { if ($this->customHandler === false || !isset($this->customHandler['subsections'])) { -- cgit v1.2.3-55-g7522