diff options
author | Simon Rettberg | 2016-05-04 18:27:28 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-04 18:27:28 +0200 |
commit | 80424b29e00609bf837119fa810b5afdadf2b4e9 (patch) | |
tree | e59c49265aeb219c4137bdf21e71262201345b99 /inc | |
parent | WIP (diff) | |
download | slx-admin-80424b29e00609bf837119fa810b5afdadf2b4e9.tar.gz slx-admin-80424b29e00609bf837119fa810b5afdadf2b4e9.tar.xz slx-admin-80424b29e00609bf837119fa810b5afdadf2b4e9.zip |
Work on translations: templates and messages work
Diffstat (limited to 'inc')
-rw-r--r-- | inc/dictionary.inc.php | 9 | ||||
-rw-r--r-- | inc/message.inc.php | 3 | ||||
-rw-r--r-- | inc/module.inc.php | 33 | ||||
-rw-r--r-- | inc/render.inc.php | 7 |
4 files changed, 29 insertions, 23 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index e8f51e24..c139c8bf 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -49,11 +49,6 @@ class Dictionary define('LANG', $language); } - public static function getArrayTemplate($template, $module, $lang = false) - { - return self::getArray($module, 'templates/' . $template, $lang); - } - public static function getArray($module, $path, $lang = false) { if ($lang === false) @@ -84,12 +79,12 @@ class Dictionary public static function getMessage($id) { - if (!preg_match('/^(\w+)\.(\w+)$/', id, $out)) { + if (!preg_match('/^(\w+)\.(.+)$/', $id, $out)) { return 'Invalid Message ID format: ' . $id; } $string = self::translate($out[1], 'messages', $out[2]); if ($string === false) { - return $id; + return "($id) ({{0}}, {{1}}, {{2}}, {{3}})"; } return $string; } diff --git a/inc/message.inc.php b/inc/message.inc.php index 96fb94c5..d6a62f4e 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -37,6 +37,9 @@ class Message */ private static function add($type, $id, $params) { + if (strstr($id, '.') === false) { + $id = Page::getModule()->getIdentifier() . '.' . $id; + } self::$list[] = array( 'type' => $type, 'id' => $id, diff --git a/inc/module.inc.php b/inc/module.inc.php index 73959471..292c744a 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -11,11 +11,11 @@ class Module */ private static $modules = false; - public static function get($name) + public static function get($name, $ignoreDepFail = false) { if (!isset(self::$modules[$name])) return false; - if (!self::resolveDeps(self::$modules[$name])) + if (!self::resolveDeps(self::$modules[$name]) && !$ignoreDepFail) return false; return self::$modules[$name]; } @@ -38,20 +38,17 @@ class Module $mod->depsChecked = true; foreach ($mod->dependencies as $dep) { if (!self::resolveDepsByName($dep)) { - if ($mod->enabled) { - error_log("Disabling module {$mod->name}: Dependency $dep failed."); - } - $mod->enabled = false; + error_log("Disabling module {$mod->name}: Dependency $dep failed."); $mod->depsMissing = true; return false; } } } - return $mod->enabled; + return !$mod->depsMissing; } /** - * @return \Module[] List of enabled modules + * @return \Module[] List of valid, enabled modules */ public static function getEnabled() { @@ -63,6 +60,17 @@ class Module return $ret; } + /** + * @return \Module[] List of all modules, including with missing deps + */ + public static function getAll() + { + foreach (self::$modules as $module) { + self::resolveDeps($module); + } + return self::$modules; + } + public static function init() { if (self::$modules !== false) @@ -86,7 +94,6 @@ class Module * Non-static */ - private $enabled = false; private $category = false; private $depsMissing = false; private $depsChecked = false; @@ -98,7 +105,6 @@ class Module { $file = 'modules/' . $name . '/config.json'; $json = @json_decode(@file_get_contents($file), true); - $this->enabled = isset($json['enabled']) && ($json['enabled'] === true || $json['enabled'] === 'true'); if (isset($json['dependencies']) && is_array($json['dependencies'])) { $this->dependencies = $json['dependencies']; } @@ -108,6 +114,11 @@ class Module $this->name = $name; } + public function hasMissingDependencies() + { + return $this->depsMissing; + } + public function newPage() { $modulePath = 'modules/' . $this->name . '/page.inc.php'; @@ -121,7 +132,7 @@ class Module public function activate() { - if ($this->activated || !$this->enabled) + if ($this->activated || $this->depsMissing) return; $this->activated = true; spl_autoload_register(function($class) { diff --git a/inc/render.inc.php b/inc/render.inc.php index b8abaf71..6a2872f7 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -185,16 +185,13 @@ class Render } // Now find all language tags in this array if (preg_match_all('/{{(lang_.+?)}}/', $html, $out) > 0) { - $dictionary = Dictionary::getArrayTemplate($template, $module); + $dictionary = Dictionary::getArray($module, 'template-tags'); $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'); - } + $dictionary = $dictionary + Dictionary::getArray('main', 'global-template-tags'); } if (empty($dictionary[$tag])) { $dictionary[$tag] = '{{' . $tag . '}}'; |