]> git.mjollnir.org Git - moodle.git/commitdiff
debug / lang string: MDL-19467 Debugging option to show where each lang string came...
authortjhunt <tjhunt>
Tue, 30 Jun 2009 01:59:48 +0000 (01:59 +0000)
committertjhunt <tjhunt>
Tue, 30 Jun 2009 01:59:48 +0000 (01:59 +0000)
New option on Administration -> Server -> Debugging called
'Show origin of languages strings' ($CFG->debugstringids).

If this is set, get_string will add the name of the lang file and the id of the string
to each string it gets, so instead of returning 'No', it will return '{No admin/checkboxno}'.

admin/settings/server.php
lang/en_utf8/admin.php
lib/moodlelib.php

index 34341dcf51d3001fd7096f7e18b7c8e76cf1ea89..74f77d93fd07ee2f6236db02d8bd1c5ca502db44 100644 (file)
@@ -99,6 +99,7 @@ $temp->add(new admin_setting_configcheckbox('debugdisplay', get_string('debugdis
 $temp->add(new admin_setting_configcheckbox('xmlstrictheaders', get_string('xmlstrictheaders', 'admin'), get_string('configxmlstrictheaders', 'admin'), 0));
 $temp->add(new admin_setting_configcheckbox('debugsmtp', get_string('debugsmtp', 'admin'), get_string('configdebugsmtp', 'admin'), 0));
 $temp->add(new admin_setting_configcheckbox('perfdebug', get_string('perfdebug', 'admin'), get_string('configperfdebug', 'admin'), '7', '15', '7'));
+$temp->add(new admin_setting_configcheckbox('debugstringids', get_string('debugstringids', 'admin'), get_string('configdebugstringids', 'admin'), 0));
 $ADMIN->add('server', $temp);
 
 
index a2192f00261127f677adbd144d73d6c7acba28b9..115230d3c951396e4d3f40a72f3671835c5ebf84 100644 (file)
@@ -276,6 +276,7 @@ $string['configstatsmaxruntime3'] = 'Specify the maximum time allowed to calcula
 $string['configstatsruntimedays'] = 'Specify the maximum number of days processed in each stats execution. When stats are up-to-date, only one day will be processed, so adjust this value depending of your server load, reducing it if shorter cron executions are needed.';
 $string['configstatsruntimestart'] = 'What time should the cronjob that does the stats processing <b>start</b>? Please specify different times if there are multiple Moodles on one physical server.';
 $string['configstatsuserthreshold'] = 'If you enter a non-zero,  non numeric value here, for ranking courses, courses with less than this number of enrolled users (all roles) will be ignored';
+$string['configdebugstringids'] = 'This option is designed to help translators. It it shows the language file and string id beside each string that is output. (Note that after you change this setting, the new setting will not take effect on the screen that says \'Changes saved\', but it will after that.)';
 $string['configstripalltitletags'] = 'Uncheck this setting to allow HTML tags in activity and resource names.';
 $string['configsupportemail'] = 'This email address will be published to users of this site as the one to email when they need general help (for example, when new users create their own accounts).  If this email is left blank then no such helpful email address is supplied.';
 $string['configsupportname'] = 'This is the name of a person or other entity offering general help via the support email or web address.';
@@ -803,6 +804,7 @@ $string['stickyblockscourseview'] = 'Course page';
 $string['stickyblocksduplicatenotice'] = 'If any block you add here is already present in a particular page, it will result in a duplicate.<br />Only the pinned block will be non-editable, the duplicate will still be editable.';
 $string['stickyblocksmymoodle'] = 'My Moodle';
 $string['stickyblockspagetype'] = 'Page type to configure';
+$string['debugstringids'] = 'Show origin of languages strings';
 $string['stripalltitletags'] = 'Remove HTML tags from all activity names';
 $string['supportemail'] = 'Support email';
 $string['supportname'] = 'Support name';
index 6bc0484d9df8d67b9cbd82150c11c992b4dc2a60..290580ff4ce05d46925466bb50035911e416012d 100644 (file)
@@ -5607,6 +5607,7 @@ class string_manager {
     private $installstrings = NULL;
     private $parentlangfile = 'langconfig.php';
     private $logtofile = false;
+    private $showstringsource = false;
     private static $singletoninstance = NULL;
 
     /**
@@ -5618,7 +5619,8 @@ class string_manager {
     public static function instance() {
         if (is_null(self::$singletoninstance)) {
             global $CFG;
-            self::$singletoninstance = new self($CFG->dirroot, $CFG->dataroot, isset($CFG->running_installer));
+            self::$singletoninstance = new self($CFG->dirroot, $CFG->dataroot,
+                    isset($CFG->running_installer), !empty($CFG->debugstringids));
             // Uncomment the followign line to log every call to get_string
             // to a file in $CFG->dataroot/temp/getstringlog/...
             // self::$singletoninstance->start_logging();
@@ -5630,12 +5632,14 @@ class string_manager {
     /**
     * string_manager construct method to instatiate this instance
     * 
-    * @param string $dirroot root directory path
-    * @param string $dataroot Path to the data root
-    * @param string $admin path to the admin directory
-    * @param bool $runninginstaller
+    * @param string $dirroot root directory path.
+    * @param string $dataroot Path to the data root.
+    * @param string $admin path to the admin directory.
+    * @param boolean $runninginstaller Set to true if we are in the installer.
+    * @param boolean $showstringsource add debug info to each string before it is
+    *       returned, to say where it came from.
     */
-    protected function __construct($dirroot, $dataroot, $runninginstaller) {
+    protected function __construct($dirroot, $dataroot, $runninginstaller, $showstringsource = false) {
         $this->dirroot = $dirroot;
         $this->corelocations = array(
             $dirroot . '/lang/' => '',
@@ -5652,6 +5656,7 @@ class string_manager {
             $this->installstrings = array_map('trim', $stringnames);
             $this->parentlangfile = 'installer.php';
         }
+        $this->showstringsource = $showstringsource;
     }
 
     /**
@@ -5962,6 +5967,9 @@ class string_manager {
                     $file = $location . $lang . $suffix . '/' . $module . '.php';
                     $result = $this->get_string_from_file($identifier, $file, $a);
                     if ($result !== false) {
+                        if ($this->showstringsource) {
+                            $result = $this->add_source_info($result, $module, $identifier, $file);
+                        }
                         return $result;
                     }
                 }
@@ -5970,6 +5978,18 @@ class string_manager {
 
         return '[[' . $identifier . ']]'; // Last resort.
     }
+
+    /**
+     * Add debug information about where this string came from.
+     */
+    protected function add_source_info($string, $module, $identifier, $file) {
+        // This should not start with '[' or we will confuse code that checks for
+        // missing language strings.
+        // It is a good idea to bracked the entire string. Sometimes on string
+        // is put inside another (For example, Default: No on the admin strings.
+        // The bracketing makes that clear.
+        return '{' . $string . ' ' . $module . '/' . $identifier . '}';
+    }
 }
 
 /**