I have got a multilingual joomla 2.5 website with sef urls enabled. The page relies heavily on ajax, so every kind of content is pulled from the server after the good old
window.onload
event. To make everything work proper and urls look nice, I want to force Joomla to always respond in the sites default language if the page loaded and the index.php of the template in invoked.
Or to describe the problem diffrent:
If an ajax-call pulls an item which is different from the default language and a page-refresh follows, joomla redirects to the homepage in the language of the last ajax-call, that is what I want to prevent.
Greetings
Got it working! The question itself was wrong! I should have been asking: "How to redirect to frontpage in default language?"
Answer:
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$languages = JLanguageHelper::getLanguages('lang_code');
$lang = JFactory::getLanguage();
$defaultLang = ( $lang->getTag() == $lang->getDefault() ) ? $lang : JLanguage::getInstance( $lang->getDefault() );
if( ! ( $lang->getTag() == $defaultLang->getTag() ) ){
$app->redirect( JRoute::_( 'index.php?lang='.$languages[ $defaultLang->getTag() ]->sef ), 'hallo', true );
}
Done!
Greetings....