2014-10-31 45 views
0

我嘗試獲取當前選定的語言。Joomla 2.5 - 函數getLanguage不給當前語言

這裏是我的代碼的一部分:

define('_JEXEC', 1); 
define('DS', DIRECTORY_SEPARATOR); 

if (file_exists(dirname(__FILE__) . '/defines.php')) { 
    include_once dirname(__FILE__) . '/defines.php'; 
} 

if (!defined('_JDEFINES')) { 
    define('JPATH_BASE', dirname(__FILE__)); 
    require_once JPATH_BASE.'/includes/defines.php'; 
} 

require_once JPATH_BASE.'/includes/framework.php'; 

$lang =& JFactory::getLanguage()->getTag(); 

和...

echo $lang; 

總是返回EN-GB。

該網站有Ger和Eng的可能性。它也改變了不同文章的語言。我不明白我在php中沒有得到當前選擇的語言。

+1

我建議你試着問你的問題了,在[堆棧的Joomla交易所(http://joomla.stackexchange.com),因爲它會得到更多的關注那裏。 – Lodder 2014-10-31 11:28:53

+0

謝謝,我會在那裏試試。 – user3433065 2014-10-31 12:28:54

回答

0

超出範圍!

這裏是解決方案:

// Set flag that this is a parent file. 
define('_JEXEC', 1); 
define('DS', DIRECTORY_SEPARATOR); 

if (file_exists(dirname(__FILE__) . '/defines.php')) { 
    include_once dirname(__FILE__) . '/defines.php'; 
} 

if (!defined('_JDEFINES')) { 
    define('JPATH_BASE', dirname(__FILE__)); 
    require_once JPATH_BASE.'/includes/defines.php'; 
} 

require_once JPATH_BASE.'/includes/framework.php'; 


// Instantiate the application. 
$app = JFactory::getApplication('site'); 

// Initialise the application. 
$app->initialise(); 


$lang =& JFactory::getLanguage()->getTag();