$lang = JFactory::getLanguage();
$lang->load('joomla', JPATH_SITE, 'xx-XX', true);
$foo = JText::_('SOME_OVERRIDE_STRING');
I would expect to get the override string in the re-loaded (xx-XX) language.
I get the default language.
3.8
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.
Status | New | ⇒ | Discussion |
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. ''
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.
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).
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.
Ah ... is it as simple as just setting \JLanguage::language?
As long as I change it back when I'm done ...
-- hugh
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.
@cheesegrits Please close if this has been resolved. Thanks.
@Quy - yup, I was just waiting to see if @mbabker had any comment, but sure.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-12-28 02:08:23 |
Closed_By | ⇒ | cheesegrits |
Why do you use
'joomla'
in your code?