Guest

meeech

By: a guest on Jun 20th, 2008  |  syntax: PHP  |  size: 1.17 KB  |  hits: 114  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2.  
  3. /**
  4.  * Class to handle translation for EE. Mainly intended for small chunks.
  5.  *
  6.  * Idea is it can be called from a template as
  7.  * {exp:xlate t="to_translate"}
  8.  **/
  9. class Xlate {
  10.        
  11.         var $return_data = "";
  12.  
  13.         var $current_language;
  14.         var $current_lang_code;
  15.         var $to_xlate;
  16.        
  17.         function Xlate()
  18.         {
  19.                
  20.                 global $TMPL, $IN, $LANG, $SESS;
  21.                
  22.                 $this->current_language = $IN->global_vars['language'];
  23.                 $this->current_lang_code = $IN->global_vars['language_code'];
  24.                
  25.                 //Assign the user language
  26.                 $SESS->userdata['language'] = $this->current_language;
  27.                
  28.                 $this->to_xlate = $TMPL->fetch_param('t');
  29.  
  30.                 $LANG->fetch_language_file('gg_mentor');
  31.  
  32.                 //And translate!
  33.                 $this->return_data = $this->in();
  34.  
  35.         }
  36.        
  37.         /**
  38.          * Takes in text to xlate
  39.          *
  40.          * Usages example: would like tags like {exp:xlate:in t="Text to translate here.        "}
  41.          * @return string
  42.          **/
  43.         function in($to_translate = false)
  44.         {
  45.                 global $LANG;
  46.                
  47.                 if($to_translate){
  48.                         $this->to_xlate = $to_translate;
  49.                 }
  50.                
  51.                 $translated = $LANG->line($this->to_xlate);
  52.                 if('' == $translated) {
  53.                         $translated = $this->to_xlate;
  54.                 }
  55.  
  56.                 return $translated;
  57.  
  58.         }
  59.        
  60. } // END class Xlate