Joomla 2.5 - 函数getLanguage不提供当前语言

时间:2014-10-31 11:06:13

标签: php joomla joomla2.5

我尝试获取当前选定的语言。

以下是我的代码部分:

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 个答案:

答案 0 :(得分: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();