From f58d513d1bc5c16eab7a0364738aed7ced20a4e6 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Fri, 3 Dec 2010 12:32:07 +0000 Subject: [PATCH] Added core translation support for modules. --- includes/hooks.inc | 28 ++++++++++++++++++++-------- includes/lang/gettext.php | 8 +++++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/includes/hooks.inc b/includes/hooks.inc index 3f769e93..d03eff1a 100644 --- a/includes/hooks.inc +++ b/includes/hooks.inc @@ -163,9 +163,7 @@ function install_hooks() { unset($code, $hook_class); } // install hooks provided by active extensions -// include($path_to_root.'/installed_extensions.php'); foreach($installed_extensions as $ext) { -// @include($path_to_root.'/'.$ext['path'].'/hooks.php'); $hook_class = 'hooks_'.$ext['package']; if ($ext['active'] && class_exists($hook_class)) { $Hooks[$ext['package']] = new $hook_class; @@ -199,10 +197,13 @@ function hook_invoke($ext, $method, &$data, $opts=null) { global $Hooks; + $ret = null; if (isset($Hooks[$ext]) && method_exists($Hooks[$ext], $method)) { - return $Hooks[$ext]->$method($data, $opts); - } else - return null; + set_ext_domain('modules/'.$ext); + $ret = $Hooks[$ext]->$method($data, $opts); + set_ext_domain(); + } + return $ret; } /* @@ -215,6 +216,7 @@ function hook_invoke_all($method, &$data, $opts=null) { $result = array(); foreach($Hooks as $ext => $hook) if (method_exists($hook, $method)) { + set_ext_domain('modules/'.$ext); $result = $hook->$method($data, $opts); if (isset($result) && is_array($result)) { $return = array_merge_recursive($return, $result); @@ -222,6 +224,7 @@ function hook_invoke_all($method, &$data, $opts=null) { $return[] = $result; } } + set_ext_domain(); return $result; } /* @@ -231,14 +234,17 @@ function hook_invoke_first($method, &$data, $opts=null) { global $Hooks; + $result = null; foreach($Hooks as $ext => $hook) { if (method_exists($hook, $method)) { + set_ext_domain('modules/'.$ext); $result = $hook->$method($data, $opts); if (isset($result)) - return $result; + break; } } - return null; + set_ext_domain(); + return $result; } /* Returns result of last hook installed. Helps implement hooks overriding by @@ -255,7 +261,13 @@ function hook_invoke_last($method, &$data, $opts=null) { $found = $ext; } } - return $found ? $Hooks[$found]->$method($data, $opts) : null; + $ret = null; + if ($found) { + set_ext_domain('modules/'.$found); + $ret = $Hooks[$found]->$method($data, $opts); + set_ext_domain(); + } + return $ret; } //------------------------------------------------------------------------------------------ // Database transaction hooks. diff --git a/includes/lang/gettext.php b/includes/lang/gettext.php index dfa778e3..4d80c9b3 100644 --- a/includes/lang/gettext.php +++ b/includes/lang/gettext.php @@ -548,8 +548,10 @@ class gettext_php_support_compiler function set_ext_domain($path='') { global $path_to_root; - $_SESSION['get_text']->add_domain($_SESSION['language']->code, - $path_to_root . ($path ? '/' : '') .$path.'/lang', - $path ? '' : $_SESSION['language']->version); + $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang'; + // ignore change when extension does not provide translation structure + if (file_exists($lang_path)) + $_SESSION['get_text']->add_domain($_SESSION['language']->code, + $lang_path, $path ? '' : $_SESSION['language']->version); } ?> -- 2.30.2