سؤال

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;
    }
}

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top