如何在Magento中實現瀏覽器檢測以加載正確的語言。Magento:瀏覽器檢測加載正確的語言
示例: 如果US用戶是衝浪到我的Magento店,Magento的應該加載路徑:..myshop ../ USA/ USA =商店代碼 如果日語用戶是衝浪到我的Magento店,Magento的應加載路徑:..myshop ../ jp/ jp =商店代碼 依此類推
我想我必須改寫.htaccess重寫Url,但我從來沒有這樣做過。我該怎麼做呢?
瀏覽器檢測代碼是怎麼樣的,我必須把它放在哪裏?在header.phtml?
非常感謝你提前!
編輯: 的index.php在CE 1.7.0.2看起來像這樣
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
include $compilerConfig;
}
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';
if (!file_exists($mageFilename)) {
if (is_dir('downloader')) {
header("Location: downloader");
} else {
echo $mageFilename." was not found";
}
exit;
}
if (file_exists($maintenanceFile)) {
include_once dirname(__FILE__) . '/errors/503.php';
exit;
}
require_once $mageFilename;
#Varien_Profiler::enable();
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);
但這Link介紹follwing代碼,你不能簡單地取代:
require_once 'app/Mage.php';
/* Determine correct language store based on browser */
function getStoreForLanguage()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
foreach (explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $accept) {
if (preg_match("!([a-z-]+)(;q=([0-9.]+))?!", trim($accept), $found)) {
$langs[] = $found[1];
$quality[] = (isset($found[3]) ? (float) $found[3] : 1.0);
}
}
// Order the codes by quality
array_multisort($quality, SORT_NUMERIC, SORT_DESC, $langs);
// get list of stores and use the store code for the key
$stores = Mage::app()->getStores(false, true);
// iterate through languages found in the accept-language header
foreach ($langs as $lang) {
$lang = substr($lang,0,2);
if (isset($stores[$lang]) && $stores[$lang]->getIsActive()) return $stores[$lang];
}
}
return Mage::app()->getStore();
}
/* Auto redirect to language store view if request is for root */
if ($_SERVER['REQUEST_URI'] === '/') {
header('Location: '.getStoreForLanguage()->getBaseUrl());
exit;
}
#Varien_Profiler::enable();
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::run();
任何人可以幫助我找出在哪裏放置或在哪裏適應index.php
再次謝謝你!
在那個magento鏈接中,它沒有解釋代碼的放置位置。我擔心我會覆蓋一些我仍然需要的東西。我正在使用CE 1.7.0.2,因此我編輯了我最初的問題。將很高興得到另一個提示,因爲我已經嘗試過,併發生錯誤。顯然是因爲我在index.php中使用了有用的smthg – furba