
meeech
By: a guest on Jun 20th, 2008 | syntax:
PHP | size: 1.17 KB | hits: 114 | expires: Never
<?php
/**
* Class to handle translation for EE. Mainly intended for small chunks.
*
* Idea is it can be called from a template as
* {exp:xlate t="to_translate"}
**/
class Xlate {
var $return_data = "";
var $current_language;
var $current_lang_code;
var $to_xlate;
function Xlate()
{
global $TMPL, $IN, $LANG, $SESS;
$this->current_language = $IN->global_vars['language'];
$this->current_lang_code = $IN->global_vars['language_code'];
//Assign the user language
$SESS->userdata['language'] = $this->current_language;
$this->to_xlate = $TMPL->fetch_param('t');
$LANG->fetch_language_file('gg_mentor');
//And translate!
$this->return_data = $this->in();
}
/**
* Takes in text to xlate
*
* Usages example: would like tags like {exp:xlate:in t="Text to translate here. "}
* @return string
**/
function in($to_translate = false)
{
global $LANG;
if($to_translate){
$this->to_xlate = $to_translate;
}
$translated = $LANG->line($this->to_xlate);
if('' == $translated) {
$translated = $this->to_xlate;
}
return $translated;
}
} // END class Xlate