MDL-15252 string manager improvements - it is possible to specify custom lang locatio...
authorPetr Skoda <skodak@moodle.org>
Sat, 10 Apr 2010 20:35:52 +0000 (20:35 +0000)
committerPetr Skoda <skodak@moodle.org>
Sat, 10 Apr 2010 20:35:52 +0000 (20:35 +0000)
lib/moodlelib.php
lib/setup.php

index d26012f..aaef17c 100644 (file)
@@ -5667,9 +5667,9 @@ function get_string_manager() {
 
     if ($singleton === null) {
         if (empty($CFG->early_install_lang)) {
-            $singleton = new amos_string_manager("$CFG->dirroot/lang", "$CFG->dataroot/lang", "$CFG->dataroot/lang");
+            $singleton = new amos_string_manager($CFG->langotherroot, $CFG->langlocalroot);
         } else {
-            $singleton = new install_string_manager("$CFG->dirroot/install/lang");
+            $singleton = new install_string_manager();
         }
     }
 
@@ -5713,27 +5713,23 @@ interface string_manager {
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class amos_string_manager implements string_manager {
-    private $coreroot;
-    private $otherroot;
-    private $localroot;
+    /** @var string location of all packs except 'en' */
+    protected $otherroot;
+    /** @var string location of all lang pack local modifications */
+    protected $localroot;
 
-    // to be optimised later
-    private $cache = array();
+    /** @var array lang string cache - it will be optimised more later */
+    protected $cache = array();
 
     /**
      * Crate new instance of amos string manager
      *
-     * TODO: precompilation in dataroot cache,
-     *       please note this does not work with current cvs lang format yet
-     *
-     * @param string $coreroot $CFG->dirroot (used in unit tests only)
      * @param string $otherroot location of downlaoded lang packs - usually $CFG->dataroot/lang
      * @param string $localroot usually the same as $otherroot
      */
-    public function __construct($coreroot, $otherroot, $localroot) {
-        $this->coreroot  = $coreroot;
-        $this->otherroot = $otherroot;
-        $this->localroot = $localroot;
+    public function __construct($otherroot, $localroot) {
+        $this->otherroot  = $otherroot;
+        $this->localroot  = $localroot;
     }
 
     /**
@@ -5767,6 +5763,8 @@ class amos_string_manager implements string_manager {
      * @return array of all string for given component and lang
      */
     protected function load_component_strings($component, $lang) {
+        global $CFG;
+
         list($plugintype, $pluginname) = normalize_component($component);
 
         if (!isset($this->cache[$lang])) {
@@ -5784,11 +5782,11 @@ class amos_string_manager implements string_manager {
             }
             $string = array();
             // first load english pack
-            if (!file_exists("$this->coreroot/en/$file.php")) {
+            if (!file_exists("$CFG->dirroot/lang/en/$file.php")) {
                 debugging("Invalid component parameter in get_string() call: $component", DEBUG_DEVELOPER);
                 return array();
             }
-            include("$this->coreroot/en/$file.php");
+            include("$CFG->dirroot/lang/en/$file.php");
             $originalkeys = array_keys($string);
             $originalkeys = array_flip($originalkeys);
 
@@ -5949,15 +5947,15 @@ class amos_string_manager implements string_manager {
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class install_string_manager implements string_manager {
-    private $installroot;
+    /** @var string location of pre-install packs for all langs */
+    protected $installroot;
 
     /**
      * Crate new instance of install string manager
-     *
-     * @param string $installroot $CFG->dirroot/install/lang (used in unit tests only)
      */
-    public function __construct($installroot) {
-        $this->installroot = $installroot;
+    public function __construct() {
+        global $CFG;
+        $this->installroot = "$CFG->dirroot/install/lang";
     }
 
     /**
index 85a207c..3ced44a 100644 (file)
@@ -260,6 +260,16 @@ if (!isset($CFG->prefix)) {   // Just in case it isn't defined in config.php
     $CFG->prefix = '';
 }
 
+// location of all languages except core English pack
+if (!isset($CFG->langotherroot)) {
+    $CFG->langotherroot = $CFG->dataroot.'/lang';
+}
+
+// location of local lang pack customisations (dirs with _local suffix)
+if (!isset($CFG->langlocalroot)) {
+    $CFG->langlocalroot = $CFG->dataroot.'/lang';
+}
+
 //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
 //the problem is that we need specific version of quickforms and hacked excel files :-(
 ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));