Come impostazione predefinita ad un'altra lingua sulla base di dominio
-
24-10-2019 - |
Domanda
sto usando Joomla con il componente di traduzione JoomFish. Questo sito ha traduzioni in tedesco e cinese. Quello che sto cercando di capire è come ottenere il dominio .de per impostazione predefinita per la traduzione in lingua tedesca (che sarebbe caricare se visitato come domain.com/de o domain.com/cn).
Qualcuno sa un modo per fare questo con forse .htaccess (una sorta di reindirizzamento)? O forse PHP? Forse impostare una sorta di variabile di sessione in base al dominio (PHP_URL_HOST)?
In questo momento ho apache2 di installazione con il wwww.domain.com come host virtuale principale, e il .de e .cn come alias.
Soluzione
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
}
Altri suggerimenti
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.