2011-10-06 69 views
0

好了,所以我得到的類文件,其中我得到的功能 - 如果我通過這樣的index.php翻譯創建多語言翻譯網頁

var $text;      

public function languages() 
{ 
    if (isset($_GET['lang']) && $_GET['lang'] != '') 
    { 
    $_SESSION['lang'] = $_GET['lang']; 
    } 
    switch($_SESSION['lang']) 
    { 
    case 'en_EN': require_once('language/lang.eng.php');break; 
    case 'lv_LV': require_once('language/lang.lv.php');break; 
    case 'ru_RU': require_once('language/lang.ru.php');break; 
    default: require_once('language/lang.eng.php'); 
    } 
    $this->text = $text; 
} 

public function translate($txt) 
{ 
    if(isset($this->text[$txt])) 
    { 
    return $this->text[$txt]; 
    } 
} 

- >echo $index->translate('search');它轉換好的,但如果我正在翻譯例如類文件中的東西 -

if ($country_rows > 0) 
{ 
    $_SESSION['country'] = $_GET['country']; 
} 
else 
{              
    $_SESSION['country'] = $this->translate('all_countries'); 
} 
} 
if ($_SESSION['country'] == '') 
{ 
    $_SESSION['country'] = $this->translate('all_countries'); 
} 

它沒有顯示出來。 在index.php文件頭我得到了包括 -

require_once('class.index.php'); 
$index = new index; 
$index->get_country(); 
$index->languages(); 

可能是什麼問題,以及如何解決它,所以我可以翻譯類文件裏面也一切?將感謝您的幫助!

+0

我們只看到星星點點這裏。你能解決這個問題嗎? – afuzzyllama

+0

好吧,正如我所說的,在類文件$ this-> translate('smth_here');不工作,它不會顯示任何東西,但在index.php我定義類索引; $首頁 - >翻譯( 'smth_here');它會翻譯得很好。 – user980952

回答

0

第一次猜測: 沒有會話開始?

session_start(); 

第二猜想: 假設你在另一個類使用$this->translate(),應先啓動對象,在下面的例子中,我通過翻譯類var $index;

<? 
include_once('class.index.php'); 
class myClass { 
    var $index; 

    public function __construct() { 
    $index = new index(); 
    $index->get_country(); 
    $index->languages(); 
    $this->index = $index; 
    } 

    public function yourFunction() { 
    echo $this->index->translate('all_countries'); 
    print_r($this->index); 
    } 
} 
?> 
+0

你好,已經做到了,沒有成功。 – user980952