2010-06-07 69 views
1

我已经制作了一个自定义的“帐户创建”脚本,以便用户可以从我的电话应用程序登录。强制通过url自定义帐户创建脚本更改语言

我想要的是能够根据其区域设置更改来自服务器的响应。所以,当我请求一个页面我想补充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"); 

?> 

回答

0

我得到它的工作

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

我发现语言必须是完全格式虽然EN-GB或zh- CN