?
avatar cheesegrits
cheesegrits
27 Dec 2017

Steps to reproduce the issue

$lang = JFactory::getLanguage();
$lang->load('joomla', JPATH_SITE, 'xx-XX', true);
$foo = JText::_('SOME_OVERRIDE_STRING');

Expected result

I would expect to get the override string in the re-loaded (xx-XX) language.

Actual result

I get the default language.

System information (as much as possible)

3.8

Additional comments

All the override loading in the Language class is done in __construct(), rather than in load(), so only ever gets loaded for the default language.

My use case (in an extension) is sending reminder emails to users, in their language, and wanting to allow the admin to override the message content with language overrides.

I've had a quick hack at moving the override code into load(), but before I get too carried away and do a PR, I just wanted to get some feedback and see if I'm missing something obvious, or there is some good reason why overrides shouldn't be re-loaded if the language is changed.

avatar cheesegrits cheesegrits - open - 27 Dec 2017
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Dec 2017
avatar infograf768
infograf768 - comment - 27 Dec 2017

Why do you use 'joomla' in your code?

avatar franz-wohlkoenig franz-wohlkoenig - change - 27 Dec 2017
Status New Discussion
avatar infograf768
infograf768 - comment - 27 Dec 2017

FYI: 'joomla' is the main xx-XX.ini file.
Maybe you could test with 'override' instead.
But if you want to load the full xx-XX package, then it should be empty i.e. ''

avatar cheesegrits
cheesegrits - comment - 27 Dec 2017

I was just going by the code ...

		$internal = $extension == 'joomla' || $extension == '';
		$filename = $internal ? $lang : $lang . '.' . $extension;
		$filename = "$path/$filename.ini";

... which does the same thing for 'joomla' or ''.

And no, 'override' won't work, as the extension or in a base path. And even if I could finagle it that way (which I'm pretty sure I can't because of the way LanguageHelper::getLanguagePath() and the above code work) there would still be all the localization methods to deal with.

And yes, the "main xx-XX.ini file" is what I need, along with overrides. I need to switch entirely to a different language as I generate each email. I handle my own extension's languages myself, and the main J! language is OK ... it's just the overrides are causing me a headache.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19183.
avatar mbabker
mbabker - comment - 27 Dec 2017

If you have to change languages, instantiate a new Language instance for each language code. Don't try to change the internal language code of the active Language instance, it can be problematic (which is exactly why setLanguage was deprecated).

avatar cheesegrits
cheesegrits - comment - 27 Dec 2017

I thought about that, but how do I then get JText::_() to use it?

Like I said, I feel like I'm missing something obvious.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19183.

avatar cheesegrits
cheesegrits - comment - 27 Dec 2017

Ah ... is it as simple as just setting \JLanguage::language?

As long as I change it back when I'm done ...

-- hugh


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19183.
avatar cheesegrits
cheesegrits - comment - 27 Dec 2017

Well, I'll be.

$origLang = \JFactory::$language;
\JFactory::$language = \JLanguage::getInstance($client['app_client___lang_code'], $this->app->get('debug_lang'));
// my stuff here that builds the email
$msg = JText::_($client['app_client___lang_slug']);
\JFactory::$language = $origLang;

... seems to have worked a treat.

Thanks guys.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19183.
avatar Quy
Quy - comment - 27 Dec 2017

@cheesegrits Please close if this has been resolved. Thanks.

avatar cheesegrits
cheesegrits - comment - 28 Dec 2017

@Quy - yup, I was just waiting to see if @mbabker had any comment, but sure.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19183.

avatar cheesegrits cheesegrits - change - 28 Dec 2017
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2017-12-28 02:08:23
Closed_By cheesegrits
avatar cheesegrits cheesegrits - close - 28 Dec 2017

Add a Comment

Login with GitHub to post a comment