From f8189f4f0bdc79a83e084c56e93e8a2ca073e4c0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 29 Apr 2016 17:43:58 +0200 Subject: More Progress; Merged changes from ufpr up to 775cdbd29f5d0f70946d1d5ff09c091e6189c9e9 --- inc/dictionary.inc.php | 2 +- inc/module.inc.php | 14 ++++++++++++-- inc/render.inc.php | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 19 deletions(-) (limited to 'inc') diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index b56106cc..e8f51e24 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -104,7 +104,7 @@ class Dictionary } $string = self::translate($out[1], 'categories', $out[2]); if ($string === false) { - return $category; + return '!!' . $category . '!!'; } return $string; } diff --git a/inc/module.inc.php b/inc/module.inc.php index 9126cb32..73959471 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -27,6 +27,11 @@ class Module return self::resolveDeps(self::$modules[$name]); } + /** + * + * @param \Module $mod the module to check + * @return boolean true iff module deps are all found and enabled + */ private static function resolveDeps($mod) { if (!$mod->depsChecked) { @@ -34,7 +39,7 @@ class Module foreach ($mod->dependencies as $dep) { if (!self::resolveDepsByName($dep)) { if ($mod->enabled) { - error_log("Disabling module $name: Dependency $dep failed."); + error_log("Disabling module {$mod->name}: Dependency $dep failed."); } $mod->enabled = false; $mod->depsMissing = true; @@ -142,10 +147,15 @@ class Module { $string = Dictionary::translate($this->name, 'module', 'module_name'); if ($string === false) { - return $this->name; + return '!!' . $this->name . '!!'; } return $string; } + + public function getPageTitle() + { + return Dictionary::translate($this->name, 'module', 'page_title'); + } public function getCategory() { diff --git a/inc/render.inc.php b/inc/render.inc.php index 14d5a810..b8abaf71 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -45,7 +45,7 @@ class Render ' - ', RENDER_DEFAULT_TITLE, self::$title, ' + ', self::$title, RENDER_DEFAULT_TITLE, ' @@ -93,7 +93,7 @@ class Render */ public static function setTitle($title) { - self::$title = ' - ' . $title; + self::$title = $title . ' - '; } /** @@ -177,28 +177,39 @@ class Render if ($html === false) { return '

Template ' . htmlspecialchars($template) . '

' . nl2br(htmlspecialchars(print_r($params, true))) . '
'; } - // Get all translated strings for this template - if($module === false){ - $module = strtolower(empty($_REQUEST['do']) ? 'main' : $_REQUEST['do']); + if($module === false) { + $module = Page::getModule()->getIdentifier(); + } + if (!is_array($params)) { + $params = array(); } - $dictionary = Dictionary::getArrayTemplate($template, $module); - // Now find all language tags in this array - preg_match_all('/{{(lang_.+?)}}/', $html, $out); - foreach ($out[1] as $tag) { - // Add untranslated strings to the dictionary, so their tag is seen in the rendered page - if (empty($dictionary[$tag])) - $dictionary[$tag] = '{{' . $tag . '}}'; + if (preg_match_all('/{{(lang_.+?)}}/', $html, $out) > 0) { + $dictionary = Dictionary::getArrayTemplate($template, $module); + $fallback = false; + foreach ($out[1] as $tag) { + // 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($module, 'module'); + if ($module !== 'main') { + $dictionary = $dictionary + Dictionary::getArray('main', 'module'); + } + } + if (empty($dictionary[$tag])) { + $dictionary[$tag] = '{{' . $tag . '}}'; + } + } + $params = $params + $dictionary; } // Always add token to parameter list - if (is_array($params) || $params === false || is_null($params)) - $params['token'] = Session::get('token'); - // Likewise, add currently selected language ( its two letter code) to params + $params['token'] = Session::get('token'); + // Likewise, add currently selected language (its two letter code) to params $params['current_lang'] = LANG; // Add desired password field type $params['password_type'] = Property::getPasswordFieldType(); // Return rendered html - return self::$mustache->render($html, array_merge($dictionary,$params)); + return self::$mustache->render($html, $params); } /** -- cgit v1.2.3-55-g7522