How to use a different domain-based language by default

I am using Joomla with the JoomFish translation component. This website has translations into German and Chinese. I am trying to figure out how to get the default .de domain for translation into German (which will load if it is visited as domain.com/de or domain.com/cn).

Does anyone know a way to do this with possibly .htaccess (some kind of redirect)? Or maybe PHP? Maybe set some sort of domain-based session variable (PHP_URL_HOST)?

I now have apache2 installed with wwww.domain.com as the primary virtual host, and .de and .cn as aliases.

+4
source share
3 answers

Welcome to SO!

Assuming your Apache has mod_setenvif enabled, add it 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 request SITE_LANGUAGE :

 switch($_SERVER['SITE_LANGUAGE']) { case 'de': // german stuff case 'zh': // chinese stuff } 
+4
source

Thanks! After adding the htaccess code, I only needed to edit /plugins/system/jfrouter.php at about 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; } } 
+3
source

What if you had a case of choosing in php based on a request for a receipt?

Something like domain.com/?lang=de combined with

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

in your code. .... will load your translator or language resource.

0
source

Source: https://habr.com/ru/post/1336824/


All Articles