Nearly every example I've seen, both in documentation and code examples, show setting the $reload parameter to \Joomla\CMS\Language\Language->load() method as true (e.g. forcing reload of the language file). Anyone have an insight into why this is the normal practice? It seems to me it's an expensive decision if the file's already loaded.

I'm kind of going crazy in a component I'm writing with how Joomla! handles language .ini files. PHP 7+'s opcache will not cache non-PHP files. I'd prefer to break all of my language files up into small files: one for the core component strings, one for each view, one for exceptions, and the like. But the overhead of all those files reads is insane.

My solution is to monkey-patch the Language object set by Factory using reflection in a plugin's onBeforeInitialise method, so that it handles both PHP and .ini translation files. The only translation file loaded by that point is en-GB.lib_joomla.ini, so I'm truncating that file in a plugin catching the installer update event after transforming it to a different PHP file.

I'm similarly using an event in a plugin to catch all extension installs and updates, and transform their language files to PHP in the template language override folder. The speed-up is huge for the complex site I'm working on. (I understand well issues with overriding core, it's not a plugin I'll release on JED).

I haven't looked to see if there's any plans for Joomla! v4 to change how the translation system works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.