diff options
author | Simon Rettberg | 2016-05-10 16:57:06 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-10 16:57:06 +0200 |
commit | 2fa2bb665d8ca5e837147f85267f865f1b8b0503 (patch) | |
tree | b2e49bb825e1cc421597a681351d04b97c91834c /inc | |
parent | Message string editing works now (diff) | |
download | slx-admin-2fa2bb665d8ca5e837147f85267f865f1b8b0503.tar.gz slx-admin-2fa2bb665d8ca5e837147f85267f865f1b8b0503.tar.xz slx-admin-2fa2bb665d8ca5e837147f85267f865f1b8b0503.zip |
Translating module strings and custom sections works
Diffstat (limited to 'inc')
-rw-r--r-- | inc/dashboard.inc.php | 40 | ||||
-rw-r--r-- | inc/dictionary.inc.php | 30 | ||||
-rw-r--r-- | inc/module.inc.php | 17 | ||||
-rw-r--r-- | inc/render.inc.php | 2 |
4 files changed, 53 insertions, 36 deletions
diff --git a/inc/dashboard.inc.php b/inc/dashboard.inc.php index ef8be110..13d713bb 100644 --- a/inc/dashboard.inc.php +++ b/inc/dashboard.inc.php @@ -7,32 +7,48 @@ class Dashboard public static function createMenu() { - $modulesAssoc = array(); + global $MENU_SETTING_SORT_ORDER, $MENU_CAT_SORT_ORDER; + $modByCategory = array(); $all = Module::getEnabled(); foreach ($all as $module) { $cat = $module->getCategory(); if ($cat === false) continue; - $modulesAssoc[$cat][] = $module; + $modByCategory[$cat][] = $module; } - $modulesArray = array(); - foreach ($modulesAssoc as $id => $list) { - $momomo = array(); - foreach ($list as $module) { - $momomo[] = array( + $categories = array(); + $catSort = array(); + foreach ($modByCategory as $catId => $modList) { + $modules = array(); + $sectionSort = array(); + foreach ($modList as $module) { + $modId = $module->getIdentifier(); + $modules[] = array( 'displayName' => $module->getDisplayName(), 'identifier' => $module->getIdentifier(), 'className' => ($module->getIdentifier() === Page::getModule()->getIdentifier()) ? 'active' : '' ); + if (isset($MENU_SETTING_SORT_ORDER[$modId])) { + $sectionSort[] = (string)($MENU_SETTING_SORT_ORDER[$modId] + 1000); + } else { + $sectionSort[] = '9999' . $modId; + } } - $modulesArray[] = array( - 'icon' => self::getCategoryIcon($id), - 'displayName' => Dictionary::getCategoryName($id), - 'modules' => $momomo + array_multisort($sectionSort, SORT_ASC, $modules); + $categories[] = array( + 'icon' => self::getCategoryIcon($catId), + 'displayName' => Dictionary::getCategoryName($catId), + 'modules' => $modules ); + if (isset($MENU_CAT_SORT_ORDER[$catId])) { + $catSort[] = (string)($MENU_CAT_SORT_ORDER[$catId] + 1000); + } else { + $catSort[] = '9999' . $catId; + } } + array_multisort($catSort, SORT_ASC, $categories); Render::setDashboard(array( - 'categories' => $modulesArray, + 'categories' => $categories, 'url' => urlencode($_SERVER['REQUEST_URI']), 'langs' => Dictionary::getLanguages(true), 'dbupdate' => Database::needSchemaUpdate(), diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index 72139601..0dafe9d9 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -68,13 +68,26 @@ class Dictionary return self::$stringCache[$file] = $json; } - public static function translate($module, $path, $string) + public static function translateFileModule($moduleId, $path, $tag) { - $strings = self::getArray($module, $path); - if (!isset($strings[$string])) { + $strings = self::getArray($moduleId, $path); + if (!isset($strings[$tag])) { return false; } - return $strings[$string]; + return $strings[$tag]; + } + + public static function translateFile($path, $tag) + { + return self::translateFileModule(Page::getModule()->getIdentifier(), $path, $tag); + } + + public static function translate($tag) + { + $string = self::translateFile('module', $tag); + if ($string !== false) + return $string; + return self::translateFileModule('main', 'global-tags', $tag); } public static function getMessage($id) @@ -82,7 +95,7 @@ class Dictionary if (!preg_match('/^(\w+)\.(.+)$/', $id, $out)) { return 'Invalid Message ID format: ' . $id; } - $string = self::translate($out[1], 'messages', $out[2]); + $string = self::translateFileModule($out[1], 'messages', $out[2]); if ($string === false) { return "($id) ({{0}}, {{1}}, {{2}}, {{3}})"; } @@ -97,15 +110,16 @@ class Dictionary if (!preg_match('/^(\w+)\.(\w+)$/', $category, $out)) { return 'Invalid Category ID format: ' . $category; } - $string = self::translate($out[1], 'categories', $out[2]); + $string = self::translateFileModule($out[1], 'categories', $out[2]); if ($string === false) { - return '!!' . $category . '!!'; + return "!!{$category}!!"; } return $string; } /** - * Get all supported languages as array + * Get all supported languages as array. + * * @param boolean $withName true = return assoc array containinc cc and name of all languages; * false = regular array containing only the ccs * @return array List of languages diff --git a/inc/module.inc.php b/inc/module.inc.php index 292c744a..261c2990 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -156,7 +156,7 @@ class Module public function getDisplayName() { - $string = Dictionary::translate($this->name, 'module', 'module_name'); + $string = Dictionary::translateFileModule($this->name, 'module', 'module_name'); if ($string === false) { return '!!' . $this->name . '!!'; } @@ -165,7 +165,7 @@ class Module public function getPageTitle() { - return Dictionary::translate($this->name, 'module', 'page_title'); + return Dictionary::translateFileModule($this->name, 'module', 'page_title'); } public function getCategory() @@ -177,18 +177,5 @@ class Module { return Dictionary::getCategoryName($this->category); } - - public function translate($tag, $section = 'module') - { - $string = Dictionary::translate($this->name, $section, $tag); - if ($string === false) { - $string = Dictionary::translate('core', $section, $tag); - } - if ($string === false) { - error_log('Translation not found. Module: ' . $this->name . ', section: ' . $section . ', tag: ' . $tag); - $string = '!!' . $tag . '!!'; - } - return $string; - } } diff --git a/inc/render.inc.php b/inc/render.inc.php index 6a2872f7..e3a23f23 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -191,7 +191,7 @@ class Render // Add untranslated strings to the dictionary, so their tag is seen in the rendered page if ($fallback === false && empty($dictionary[$tag])) { $fallback = true; // Fallback to general dictionary of module - $dictionary = $dictionary + Dictionary::getArray('main', 'global-template-tags'); + $dictionary = $dictionary + Dictionary::getArray('main', 'global-tags'); } if (empty($dictionary[$tag])) { $dictionary[$tag] = '{{' . $tag . '}}'; |