J3 Issue ?
avatar mbabker
mbabker
25 Oct 2018

ActionlogsHelper::loadTranslationFiles() can fail over on:

  • Loading language strings for a site component element
  • Loading language strings for an admin module
  • Loading language strings for site templates

(Look at the extension paths for all of those)

Originally posted by @mbabker in #22701 (comment)

avatar mbabker mbabker - open - 25 Oct 2018
avatar joomla-cms-bot joomla-cms-bot - change - 25 Oct 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Oct 2018
avatar infograf768
infograf768 - comment - 25 Oct 2018
  1. Templates
    Afaik, templates names are never translated. Therefore no need to translate the name when installing, updating. (See our core templates as example). Modifying a template file is not added yet to actionlogs, but it would be the same situation if that was added.

When modifying a template style (admin or site), actions pick up the title of the style, therefore this also does not need to be translated.

In both cases loading the ini file is no use imho.

  1. Modules.
    When modifying a module (admin or site), actions pick up the title of the module, therefore this also does not need to be translated.
    We do need the ini when installing, updating.

  2. Site Components
    we do need to load the ini.

I propose to load the lang in each case instead of globally (which also includes the code for templates, but can be omitted if my analysis above is accepted. In fact, the tpl case could be totally ignored)

	public static function loadTranslationFiles($extension)
	{
		static $cache = array();
		$extension = strtolower($extension);

		if (isset($cache[$extension]))
		{
			return;
		}

		$lang = JFactory::getLanguage();

		switch (substr($extension, 0, 3))
		{
			case 'com':
			default:
				$source = JPATH_ADMINISTRATOR . '/components/' . $extension;

				if (file_exists($source))
				{
					$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
						|| $lang->load($extension, $source, null, false, true);

					if (!$lang->hasKey(strtoupper($extension)))
					{
						$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
							|| $lang->load($extension . '.sys', $source, null, false, true);
					}
				}
				else
				{
					$source = JPATH_SITE . '/components/' . $extension;

					if (file_exists($source))
					{
						$lang->load($extension, JPATH_SITE, null, false, true)
							|| $lang->load($extension, $source, null, false, true);

						if (!$lang->hasKey(strtoupper($extension)))
						{
							$lang->load($extension . '.sys', JPATH_SITE, null, false, true)
								|| $lang->load($extension . '.sys', $source, null, false, true);
						}
					}
				}
				break;

			case 'lib':
				$source = JPATH_LIBRARIES . '/' . substr($extension, 4);
				$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
					|| $lang->load($extension, $source, null, false, true);

				if (!$lang->hasKey(strtoupper($extension)))
				{
					$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
						|| $lang->load($extension . '.sys', $source, null, false, true);
				}
				break;

			case 'mod':
				$source = JPATH_ADMINISTRATOR . '/modules/' . $extension;

				if (file_exists($source))
				{
					$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
						|| $lang->load($extension, $source, null, false, true);

					if (!$lang->hasKey(strtoupper($extension)))
					{
						$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
							|| $lang->load($extension . '.sys', $source, null, false, true);
					}
				}
				else
				{
					$source = JPATH_SITE . '/modules/' . $extension;

					if (file_exists($source))
					{
						$lang->load($extension, JPATH_SITE, null, false, true)
							|| $lang->load($extension, $source, null, false, true);

						if (!$lang->hasKey(strtoupper($extension)))
						{
							$lang->load($extension . '.sys', JPATH_SITE, null, false, true)
								|| $lang->load($extension . '.sys', $source, null, false, true);
						}
					}
				}
				break;

			case 'plg':
				$parts = explode('_', $extension, 3);
				$source = JPATH_PLUGINS . '/' . $parts[1] . '/' . $parts[2];

				$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
					|| $lang->load($extension, $source, null, false, true);

				if (!$lang->hasKey(strtoupper($extension)))
				{
					$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
						|| $lang->load($extension . '.sys', $source, null, false, true);
				}
				break;

			case 'tpl':
				$source = JPATH_ADMINISTRATOR . '/templates/' . substr($extension, 4);

				if (file_exists($source))
				{
					$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
						|| $lang->load($extension, $source, null, false, true);

					if (!$lang->hasKey(strtoupper($extension)))
					{
						$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
							|| $lang->load($extension . '.sys', $source, null, false, true);
					}
				}
				else
				{
					$source = JPATH_SITE . '/templates/' . substr($extension, 4);

					if (file_exists($source))
					{
						$lang->load($extension, JPATH_SITE, null, false, true)
							|| $lang->load($extension, $source, null, false, true);

						if (!$lang->hasKey(strtoupper($extension)))
						{
							$lang->load($extension . '.sys', JPATH_SITE, null, false, true)
								|| $lang->load($extension . '.sys', $source, null, false, true);
						}
					}
				}
				break;

		}

		$cache[$extension] = true;
	}

I know it is heavy code, but I tested it ok here. It is somehow similar to what you propose here for the extension name:
#22701 (comment)

What do you think?

avatar brianteeman brianteeman - change - 30 Oct 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 30 Oct 2018
avatar brianteeman brianteeman - change - 30 Oct 2018
Labels Removed: J3 Issue
avatar brianteeman brianteeman - unlabeled - 30 Oct 2018
avatar brianteeman brianteeman - unlabeled - 30 Oct 2018
avatar brianteeman brianteeman - change - 30 Oct 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 30 Oct 2018
avatar alikon
alikon - comment - 9 Nov 2018

is this a god fit for ActionlogsHelper ?

shouldn't be an api feature ?

avatar GeraintEdwards
GeraintEdwards - comment - 12 Nov 2018

I'm going to work on a full PR for this issue (and #22701) primarily with specific reference to com_installer. The heart of the issue, from what I can see, is that the ActionLogs component doesn't load the correct language files. There are 2 reasons for this:

  1. The extension name passed from com_installer is based on the manifest file as opposed to the actual extension name
  2. For some types of extension the current code loads the files from the wrong folder (backend v.s. frontend)

As @mbabker points out amodule could be frontend or backend so we need to know which language file to use.

There is a further issue (in general, not just com_installer) which is that for components the language string could be in a frontend OR backend language file so it should load one and check for a key and loading the other if needed, before falling back to .sys.ini files as a backstop.

My starting point is that com_installer manage extensions DOES already get the correct language files/strings to ActionLogs is just being sloppy from com_installer's point of view. So we need to mimic the translation algorithm from com_installer/manage - in essence using the content of the extension table as opposed to the name from the manifest file. We have the $eid so this is doable without much effort, but we risk duplicating the code from within com_installer.

So, a question before I dive in, are we ok replicating some of the com_installer code or should it be moved to a 'library'??

avatar mbabker
mbabker - comment - 12 Nov 2018

Some of the loader logic could probably be a library helper method.

As for figuring out the right client, right now that's not being stored in the messages, we need to add that for extension CRUD actions to distinguish admin and site languages, modules, and templates at a minimum.

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status New Discussion
avatar brianteeman
brianteeman - comment - 11 Mar 2019

@GeraintEdwards did you ever write anything?

avatar franz-wohlkoenig franz-wohlkoenig - change - 28 Mar 2019
Category com_csp
avatar mbabker mbabker - change - 19 Jul 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-07-19 15:52:41
Closed_By mbabker
avatar mbabker mbabker - close - 19 Jul 2019

Add a Comment

Login with GitHub to post a comment