includes/lang.php
changeset 376 66732bd4532c
parent 372 5bd429428101
child 377 bb3e6c3bd4f4
equal deleted inserted replaced
375:8d0e3a5a6990 376:66732bd4532c
   454    * @return string
   454    * @return string
   455    */
   455    */
   456   
   456   
   457   function get($string_id, $substitutions = false)
   457   function get($string_id, $substitutions = false)
   458   {
   458   {
       
   459     if ( !is_array($substitutions) )
       
   460       $substitutions = array();
       
   461     return $this->substitute($this->get_uncensored($string_id), $substitutions);
       
   462   }
       
   463   
       
   464   /**
       
   465    * The same as get(), but does not perform any substitution or filtering. Used in get() (of course) and in the admin panel, where
       
   466    * strings are updated only if they were changed.
       
   467    *
       
   468    * @param string ID of the string to fetch. This will always be in the format of category_stringid.
       
   469    * @param array Optional. Associative array of substitutions.
       
   470    * @return string
       
   471    */
       
   472   
       
   473   function get_uncensored($string_id, $substitutions = false)
       
   474   {
   459     // Extract the category and string ID
   475     // Extract the category and string ID
   460     $category = substr($string_id, 0, ( strpos($string_id, '_') ));
   476     $category = substr($string_id, 0, ( strpos($string_id, '_') ));
   461     $string_name = substr($string_id, ( strpos($string_id, '_') + 1 ));
   477     $string_name = substr($string_id, ( strpos($string_id, '_') + 1 ));
   462     $found = false;
   478     $found = false;
   463     if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) )
   479     if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) )
   484         $lang_default = ( $x = getConfig('default_language') ) ? intval($x) : $this->lang_id;
   500         $lang_default = ( $x = getConfig('default_language') ) ? intval($x) : $this->lang_id;
   485         if ( $lang_default != $this->lang_id )
   501         if ( $lang_default != $this->lang_id )
   486         {
   502         {
   487           if ( !is_object($this->default) )
   503           if ( !is_object($this->default) )
   488             $this->default = new Language($lang_default);
   504             $this->default = new Language($lang_default);
   489           return $this->default->get($string_id, $substitutions);
   505           return $this->default->get_uncensored($string_id);
   490         }
   506         }
   491       }
   507       }
   492     }
   508     }
   493     if ( !$found )
   509     if ( !$found )
   494     {
   510     {
   495       // Alright, it's nowhere. Return the input, grumble grumble...
   511       // Alright, it's nowhere. Return the input, grumble grumble...
   496       return $string_id;
   512       return $string_id;
   497     }
   513     }
   498     // Found it!
   514     // Found it!
   499     // Perform substitutions.
   515     return $string;
   500     // if ( is_array($substitutions) )
       
   501     //   die('<pre>' . print_r($substitutions, true) . '</pre>');
       
   502     if ( !is_array($substitutions) )
       
   503       $substitutions = array();
       
   504     return $this->substitute($string, $substitutions);
       
   505   }
   516   }
   506   
   517   
   507   /**
   518   /**
   508    * Processes substitutions.
   519    * Processes substitutions.
   509    * @param string
   520    * @param string