Language file needs to be loaded to cater for 3rd party components using the MailTemplate
Without the language files being loaded the 3rd party components can't adequately utilise this whole component.
In the tmpl file for the list view (administrator/components/com_mails/tmpl/templates/default.php) add the following:
Insert line 13
use \Joomla\CMS\Factory;
Insert line 74
// load components language file
Factory::getLanguage()->load($component, JPATH_ADMINISTRATOR);
Replace line 79 with
<?php echo Text::_(STRTOUPPER($component) . '_MAIL_' . STRTOUPPER($sub_id) . '_TITLE'); ?>
And 103 with
<?php echo Text::_(STRTOUPPER($component) . '_MAIL_' . STRTOUPPER($sub_id) . '_DESC'); ?>
Possibly reduced speed to load.
Labels |
Added:
No Code Attached Yet
|
Title |
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-01-08 14:49:30 |
Closed_By | ⇒ | joomdonation |
Thank you for highlighting all this for me and I apologise for wasting time. I will read through this code to see why my components language text didn't work as I expected it. Cheers.
Ahhh so the admin list view of the template records is using the site language file rather than the admin one, this is why my language didn't get picked up. No problems I will change my component accordingly. (I keep learning every time I delve into the code and I must do more delving.) Thanks again for your guidance. Cheers.
Ahhh so the admin list view of the template records is using the site language file rather than the admin one, this is why my language didn't get picked up
It is not right. It looks for admin language file, not site language file. Not sure how you insert the mail templates for your extension into #__mail_templates
table? I would suggest you to look at that table, find the records related to your extension and check data of extension
column. It should be set to the name of the extension (like com_contact, com_banner..). I guess right now, it is empty and that's why the language file of your component is not loaded. There is a PR for fixing that behavior #39540 (I know you commented on that PR, just want to make sure it is set to right value)
For example, here are the language items used for com_contact component and it's from admin language file https://github.com/joomla/joomla-cms/blob/4.2-dev/administrator/language/en-GB/com_contact.ini#L151-L154
To see exactly which language files are loaded you should enable the language debug in global configuration
Apologies, I don't know what I was looking at, but yes all is good now. Cheers.
We load language files for third party extensions already. It is called here https://github.com/joomla/joomla-cms/blob/4.2-dev/administrator/components/com_mails/src/View/Templates/HtmlView.php#L120 and the actual code which loads language file can be found here https://github.com/joomla/joomla-cms/blob/4.2-dev/administrator/components/com_mails/src/Helper/MailsHelper.php#L67 . If you read the code, it loads language files for not only component but also module and plugin. So your suggested code is not valid
As for your suggested code change on line 79 and 103 (the lines number is not right to me), it is not needed, too. Adding strotoupper is not required because it is handled automatically by our language API, see https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Language/Language.php#L317
Base on the above information, this issue is invalid, so I'm closing it. Feel free to re-open if there are something more to discuss. Thanks !