5

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.

Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
Michael
  • 891
  • 2
  • 16
  • 32

3 Answers3

5

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
}
Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
  • 1
    Thank you! This pretty much did it. All i had to do is edit /plugins/system/jfrouter.php at about line 145 added your code with the same logic as line 145. – Michael Jan 24 '11 at 18:15
3

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;
    }
}
Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
Michael
  • 891
  • 2
  • 16
  • 32
0

What if you had a select case in php based on a get request?

Something like domain.com/?lang=de in conjunction with

$lang = "default";
if (isset($_GET['lang'])) {
    $lang = $_GET['lang'];
}   
if ($lang != "default") {
    if($lang == "de") {
        ....

in your code. .... would be where you load your translator or language resource.

Bhavya
  • 283
  • 1
  • 12