MDL-22059 fixing install_string_manager to work with new installer language formats
authorPetr Skoda <skodak@moodle.org>
Sun, 11 Apr 2010 18:26:19 +0000 (18:26 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 11 Apr 2010 18:26:19 +0000 (18:26 +0000)
install.php
lib/moodlelib.php

index 71b91f5..9b20c07 100644 (file)
@@ -146,6 +146,8 @@ $CFG->httpswwwroot         = $CFG->wwwroot;
 $CFG->dataroot             = $config->dataroot;
 $CFG->admin                = $config->admin;
 $CFG->docroot              = 'http://docs.moodle.org';
+$CFG->langotherroot        = $CFG->dataroot.'/lang';
+$CFG->langlocalroot        = $CFG->dataroot.'/lang';
 $CFG->directorypermissions = 00777;
 $CFG->running_installer    = true;
 $CFG->early_install_lang   = true;
@@ -362,7 +364,7 @@ if ($config->stage == INSTALL_DOWNLOADLANG) {
         if ($cd->install() == COMPONENT_ERROR) {
             if ($cd->get_error() == 'remotedownloaderror') {
                 $a = new stdClass();
-                $a->url  = 'http://download.moodle.org/lang20/'.$INSTALL['language'].'.zip';
+                $a->url  = 'http://download.moodle.org/lang20/'.$config->lang.'.zip';
                 $a->dest = $CFG->dataroot.'/lang';
                 $downloaderror = get_string($cd->get_error(), 'error', $a);
             } else {
index a533f00..b5b1123 100644 (file)
@@ -6038,13 +6038,39 @@ class install_string_manager implements string_manager {
      * @return string The String !
      */
     public function get_string($identifier, $component = '', $a = NULL) {
+        if (!$component) {
+            $component = 'moodle';
+        }
         $lang = current_language();
 
+        //get parent lang
+        $parent = '';
+        if ($lang !== 'en' and $identifier !== 'parentlanguage' and $component !== 'langconfig') {
+            if (file_exists("$this->installroot/$lang/langconfig.php")) {
+                $string = array();
+                include("$this->installroot/$lang/langconfig.php");
+                if (isset($string['parentlanguage'])) {
+                    $parent = $string['parentlanguage'];
+                }
+                unset($string);
+            }
+        }
+
+        // include en string first
+        if (!file_exists("$this->installroot/en/$component.php")) {
+            return "[[$identifier]]";
+        }
         $string = array();
-        include("$this->installroot/en/installer.php");
+        include("$this->installroot/en/$component.php");
+
+        // now override en with parent if defined
+        if ($parent and $parent !== 'en' and file_exists("$this->installroot/$parent/$component.php")) {
+            include("$this->installroot/$parent/$component.php");
+        }
 
-        if (file_exists("$this->installroot/$lang/installer.php") and $lang !== 'en') {
-            include("$this->installroot/$lang/installer.php");
+        // finally override with requested language
+        if ($lang !== 'en' and file_exists("$this->installroot/$lang/$component.php")) {
+            include("$this->installroot/$lang/$component.php");
         }
 
         if (!isset($string[$identifier])) {
@@ -6063,16 +6089,14 @@ class install_string_manager implements string_manager {
                         // we do not support numeric keys - sorry!
                         continue;
                     }
-                    $search[]  = '$a->'.$key.'';
-                    //$search[]  = '{$a->'.$key.'}'; // TODO: uncomment after switch to {a->aa}
+                    $search[]  = '{$a->'.$key.'}';
                     $replace[] = (string)$value;
                 }
                 if ($search) {
                     $string = str_replace($search, $replace, $string);
                 }
             } else {
-                $string = str_replace('$a', (string)$a, $string);
-                //$string = str_replace('{$a}', (string)$a, $string); // TODO: uncomment after switch to {a}
+                $string = str_replace('{$a}', (string)$a, $string);
             }
         }
 
@@ -6099,9 +6123,9 @@ class install_string_manager implements string_manager {
         asort($langdirs);
         // Get some info from each lang
         foreach ($langdirs as $lang) {
-            if (file_exists($this->installroot.'/'.$lang.'/installer.php')) {
+            if (file_exists($this->installroot.'/'.$lang.'/langconfig.php')) {
                 $string = array();
-                include($this->installroot.'/'.$lang.'/installer.php');
+                include($this->installroot.'/'.$lang.'/langconfig.php');
                 if (!empty($string['thislanguage'])) {
                     $languages[$lang] = $string['thislanguage'].' ('.$lang.')';
                 }