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 --- .../translation/lang/de/template-tags.json | 1 + .../translation/lang/en/template-tags.json | 1 + modules-available/translation/page.inc.php | 68 +++++++++++++++++++++- .../translation/templates/menu-category-list.html | 23 ++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 modules-available/translation/templates/menu-category-list.html (limited to 'modules-available/translation') diff --git a/modules-available/translation/lang/de/template-tags.json b/modules-available/translation/lang/de/template-tags.json index 3f381751..b8497bd9 100644 --- a/modules-available/translation/lang/de/template-tags.json +++ b/modules-available/translation/lang/de/template-tags.json @@ -2,6 +2,7 @@ "lang_createTag": "Tag erstellen", "lang_global": "Global", "lang_globalTooltip": "Dieser Tag ist global verf\u00fcgbar und braucht normalerweise nicht explizit f\u00fcr dieses Modul \u00fcbersetzt zu werden", + "lang_menuCategories": "Men\u00fckategorien", "lang_messages": "Benachrichtigungen", "lang_missing": "Fehlend", "lang_module": "Modul", diff --git a/modules-available/translation/lang/en/template-tags.json b/modules-available/translation/lang/en/template-tags.json index 5aee54c3..ec2a26a3 100644 --- a/modules-available/translation/lang/en/template-tags.json +++ b/modules-available/translation/lang/en/template-tags.json @@ -2,6 +2,7 @@ "lang_createTag": "Create Tag", "lang_global": "Global", "lang_globalTooltip": "This tag is global; usually there is no need to translate it explicitly for this module", + "lang_menuCategories": "Menu categories", "lang_messages": "Messages", "lang_missing": "Missing", "lang_module": "Module", 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'])) { diff --git a/modules-available/translation/templates/menu-category-list.html b/modules-available/translation/templates/menu-category-list.html new file mode 100644 index 00000000..4a0df819 --- /dev/null +++ b/modules-available/translation/templates/menu-category-list.html @@ -0,0 +1,23 @@ +
+
+
+ {{lang_menuCategories}} +
+
+
+
+ {{#langs}} + {{name}} » +
    +
  • {{lang_missing}}: {{missing}}
  • +
  • {{lang_unused}}: {{unused}}
  • +
+ {{/langs}} +
+
+ {{lang_tags}}: {{tagcount}} +
+
+
+
+
\ No newline at end of file -- cgit v1.2.3-55-g7522