强制语言从自定义帐户创建脚本更改为URL

时间:2010-06-07 16:48:34

标签: joomla joomla1.5

我制作了一个自定义的“帐户创建”脚本,以便用户可以从我的手机应用程序登录。

我想要的是能够根据服务器的区域设置更改服务器的响应。因此,当我请求页面时,我会添加lang = en或lang = zh等。

这有效

  

http://mysite.com/phone/my_custom_account_creation.php?lang=en

响应:

<resource classification="error" code="Error (Code: 500)"> 
<message>Please enter your name:</message> 
</resource>

这不起作用:

  

http://mysite.com/phone/my_custom_account_creation.php?lang=zh

响应:

<resource classification="error" code="Error (Code: 500)"> 
<message>Please enter your name:</message> 
</resource>

如果我将Joomla的默认语言设置为中文,那就可以了。

<resource classification="error" code="Error (Code: 500)"> 
<message>请输入您的姓名。</message> 
</resource>

但是

  

http://mysite.com/phone/my_custom_account_creation.php?lang=en   不起作用,而是继续显示中文版。

我可以在这做什么?

这是我用于注册的代码:

<?php
header ("content-type: text/xml");

/*
 * Register a user from a phone interface using JAVA
 */

define( '_JEXEC', 1 ); 
//define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define('JPATH_BASE', dirname(__FILE__)."/../.." );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );  

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

//My functions
require_once('../shared_functions.php');

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

//Don't use tokens for registration
//JRequest::checkToken() or jexit( 'Invalid Token' );

$user         = clone(JFactory::getUser());
$pathway          = & $mainframe->getPathway();
$config       = & JFactory::getConfig();
$authorize        = & JFactory::getACL();
$document       = & JFactory::getDocument();

$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0')
    {
        xmlError("Access Forbidden (Code 403)","Registration has been temporarily disabled");
        //JError::raiseError( 403, JText::_( 'Access Forbidden' ));
        return;
    }

$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype)
    {
        $newUsertype = 'Registered';
    }

if (!$user->bind( JRequest::get('post'), 'usertype' ))
    {
        xmlError("Error (Code: 500)",$user->getError());
        return;
        //JError::raiseError( 500, $user->getError());
    }

$user->set('id', 0);
$user->set('usertype', '');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());


$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
    {
        jimport('joomla.user.helper');
        $user->set('activation', md5( JUserHelper::genRandomPassword()) );
        $user->set('block', '1');
    }

if (!$user->save()) { // if the user is NOT saved...
    xmlError("Error (Code: 500)",$user->getError());
    //JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
    //return false; // if you're in a method/function return false
}


xmlMessage("ok",CODE_ACCOUNT_CREATED,"Success");

?>

1 个答案:

答案 0 :(得分:0)

我得到了它的工作

$lang =& JFactory::getLanguage();
$lang->setLanguage( $_GET['lang'] );
$lang->load();

我发现语言必须是完整格式,但是en-GB或zh-CN