Incorrect Language Override in external script for ajax

For Joomla! 3.x Coding related discussions, please use:

Moderator: ooffick

Forum rules
Please use the mailing list here: rather than this forum.
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Apr 02, 2019 11:08 pm

Incorrect Language Override in external script for ajax

Post by steep » Tue Apr 02, 2019 11:44 pm

Hey guys, I did a search for this issue and did not find anything.

I'm working on a component that uses ajax by initializing joomla in a separate script where I can send requests. I am trying to apply the logged in user's language (English or French) in any content or messages I send back from my component by using getLanguage() and load(). The code might look something like this:

Code: Select all

//Require stuff here
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
$language = JFactory::getLanguage();
$language->load('my_component', JPATH_SITE, $user->getParam('language'), true);
//Do stuff here
This works except for the case where I use an English override INI file. If an English override INI file is present, it overrides French labels as well.

It seems like this is because the override file is loaded in the Language constructor (/libraries/src/language) and when load() is called for a different language, the overrides have already been set to the site default language. There doesn't seem to be a method to update the overrides once Language has been constructed.

1) Is there a way to change the site language BEFORE the Language constructor is called? Maybe a method I could use on the Joomla application to make the language align with the user.

2) Is there a way to reload the override data AFTER the Language constructor is called? I can call load() to reload a new language file but it would be helpful if I could reload the overrides as well.

3) If neither #1 or #2 are possible, should this be an issue for the Joomla dev team? It would be nice to be able to have multiple languages AND use overrides when using external scripts for ajax.


Return to “Joomla! 3.x Coding”