i'm using Joomla with the JoomFish translation component. This website has german and chinese translations. What i'm trying to figure out is how to get the .de domain to default to the german language translation ( which would load if visited as domain.com/de or domain.com/cn ).
Does anyone know a way to do this with maybe .htaccess ( some kind of redirect )? Or possibly PHP? Maybe set some kind of session variable based on the domain (PHP_URL_HOST) ?
Right now i have apache2 setup with the wwww.domain.com as the main virtual host, and the .de and .cn as aliases.
Welcome to SO!
Provided, your Apache has mod_setenvif
enabled, add this to your .htaccess
file:
# Site accessed via "example.de" or "example.cn"
SetEnvIf Host "\.de$" SITE_LANGUAGE=de
SetEnvIf Host "\.cn$" SITE_LANGUAGE=zh
# URL dependent
SetEnvIf Request_URI "^/de/" SITE_LANGUAGE=de
SetEnvIf Request_URI "^/cn/" SITE_LANGUAGE=zh
Then, in your PHP script you can query SITE_LANGUAGE
:
switch($_SERVER['SITE_LANGUAGE']) {
case 'de':
// german stuff
case 'zh':
// chinese stuff
}
Thank you! After adding the htaccess code, all I had to do is edit /plugins/system/jfrouter.php
at about around 145:
if (isset($_SERVER['SITE_LANGUAGE'])) {
switch($_SERVER['SITE_LANGUAGE']) {
case 'de':
$client_lang = 'de';
$lang_known = true;
JRequest::setVar('lang', 'de' );
break;
case 'zh':
$client_lang = 'zh';
$lang_known = true;
JRequest::setVar('lang', 'zh' );
break;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With