Page 1 of 1

Language switch using PHP

Posted: Wed Jun 25, 2014 4:23 pm
by developeronex
Hi,

I am trying to switch my language in a AJAX Call unfortunately couldn't do it. Default language of my site is German.

For one of the the AJAX request alone I need to switch to English.

I have added German and English languages to language packs.

Code: Select all

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', substr(dirname(__FILE__),0,strrpos(dirname(__FILE__), DS, strrpos(dirname(__FILE__), DS) - strlen(dirname(__FILE__)) - 7))); //getting the root path

require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =JFactory::getApplication('site');
$mainframe->initialise();
$session = JFactory::getSession();

//Till this all seems to work
$lang = JFactory::getLanguage();
//At this stage it says de-DE $lang->getTag()

//forcing my page to be en-GB.
$lang->load(null,null,"en-GB",true);

//Still says de-DE $lang->getTag() and JText::_('KEY') - is not translating, just returns me KEY

Any help appreciated.

Kind Regards
Kay