简体   繁体   中英

Joomla change language in PHP (index.php) depend on domain name

I would like to manually set language in PHP (index.php) before load the page depend on domain name. For example I need something like this:

<?php    
$server = filter_var($_SERVER['SERVER_NAME'], FILTER_SANITIZE_STRING);
if($server == 'domain1') {
   // How can i set current language to sk-SK?
} else {
   // How can i set current language to en-GB?
}

Try with:

$lang = JFactory::getLanguage();
$lang->setLanguage('sk-SK' );
$lang->load();

You can create a custom system plugin that runs onAfterInitialize and performs the requested task. See https://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla for basic instructions on how to build a plugin.

You may want to duplicate and rename the languageFilter plugin since you were already able to make it work.

我黑了languagefilter插件,现在可以了,但是它不正确,因为在将Joomla更新到新版本文件时,它会被覆盖:-(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM