2010-06-07 72 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