Skip to content

Commit

Permalink
Revert the translate function in the CMSPlugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Jul 2, 2022
1 parent ce5f12c commit 7c3ade1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 39 deletions.
28 changes: 0 additions & 28 deletions libraries/src/Plugin/CMSPlugin.php
Expand Up @@ -172,34 +172,6 @@ public function loadLanguage($extension = '', $basePath = JPATH_ADMINISTRATOR)
|| $lang->load($extension, JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name);
}

/**
* Translates the given key with the local applications language. If arguments are available, then
* injects them into the translated string.
*
* @param string $key The key to translate
* @param mixed[] $arguments The arguments
*
* @return string The translated string
*
* @since 4.2.0
*
* @see sprintf
*/
protected function translate(string $key): string
{
$language = $this->getApplication()->getLanguage();

$arguments = \func_get_args();

if (count($arguments) > 1) {
$arguments[0] = $language->_($key);

return \call_user_func_array('sprintf', $arguments);
}

return $language->_($key);
}

/**
* Registers legacy Listeners to the Dispatcher, emulating how plugins worked under Joomla! 3.x and below.
*
Expand Down
6 changes: 3 additions & 3 deletions plugins/api-authentication/basic/src/Extension/Basic.php
Expand Up @@ -70,7 +70,7 @@ public function onUserAuthenticate($credentials, $options, &$response)

if ($password === '') {
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = $this->translate('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');

return;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
} else {
// Invalid password
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = $this->translate('JGLOBAL_AUTH_INVALID_PASS');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_INVALID_PASS');
}
} else {
// Let's hash the entered password even if we don't have a matching user for some extra response time
Expand All @@ -115,7 +115,7 @@ public function onUserAuthenticate($credentials, $options, &$response)

// Invalid user
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = $this->translate('JGLOBAL_AUTH_NO_USER');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_NO_USER');
}
}
}
2 changes: 1 addition & 1 deletion plugins/api-authentication/token/src/Extension/Token.php
Expand Up @@ -95,7 +95,7 @@ public function onUserAuthenticate($credentials, $options, &$response): void
// Default response is authentication failure.
$response->type = 'Token';
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = $this->translate('JGLOBAL_AUTH_FAIL');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_FAIL');

/**
* First look for an HTTP Authorization header with the following format:
Expand Down
6 changes: 3 additions & 3 deletions plugins/task/requests/src/Extension/Requests.php
Expand Up @@ -128,7 +128,7 @@ protected function makeGetRequest(ExecuteTaskEvent $event): int
try {
$response = $this->httpFactory->getHttp([])->get($url, $headers, $timeout);
} catch (Exception $e) {
$this->logTask($this->translate('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_TIMEOUT'));
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_TIMEOUT'));

return TaskStatus::TIMEOUT;
}
Expand All @@ -144,7 +144,7 @@ protected function makeGetRequest(ExecuteTaskEvent $event): int
$this->snapshot['output_file'] = $responseFilename;
$responseStatus = 'SAVED';
} catch (Exception $e) {
$this->logTask($this->translate('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_UNWRITEABLE_OUTPUT'), 'error');
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_UNWRITEABLE_OUTPUT'), 'error');
$responseStatus = 'NOT_SAVED';
}

Expand All @@ -155,7 +155,7 @@ protected function makeGetRequest(ExecuteTaskEvent $event): int
> Response: $responseStatus
EOF;

$this->logTask($this->translate('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_RESPONSE', $responseCode));
$this->logTask(sprintf($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_RESPONSE'), $responseCode));

if ($response->code !== 200) {
return TaskStatus::KNOCKOUT;
Expand Down
8 changes: 4 additions & 4 deletions plugins/task/sitestatus/src/Extension/SiteStatus.php
Expand Up @@ -139,7 +139,7 @@ public function alterSiteStatus(ExecuteTaskEvent $event): void

$newStatus = $config['offline'] ? 'offline' : 'online';
$exit = $this->writeConfigFile(new Registry($config));
$this->logTask($this->translate('PLG_TASK_SITE_STATUS_TASK_LOG_SITE_STATUS', $oldStatus, $newStatus));
$this->logTask(sprintf($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_TASK_LOG_SITE_STATUS'), $oldStatus, $newStatus));

$this->endRoutine($event, $exit);
}
Expand All @@ -161,15 +161,15 @@ private function writeConfigFile(Registry $config): int

// Attempt to make the file writeable.
if (file_exists($file) && Path::isOwner($file) && !Path::setPermissions($file)) {
$this->logTask($this->translate('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice');
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice');
}

try {
// Attempt to write the configuration file as a PHP class named JConfig.
$configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
File::write($file, $configuration);
} catch (Exception $e) {
$this->logTask($this->translate('PLG_TASK_SITE_STATUS_ERROR_WRITE_FAILED'), 'error');
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_WRITE_FAILED'), 'error');

return Status::KNOCKOUT;
}
Expand All @@ -181,7 +181,7 @@ private function writeConfigFile(Registry $config): int

// Attempt to make the file un-writeable.
if (Path::isOwner($file) && !Path::setPermissions($file, '0444')) {
$this->logTask($this->translate('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice');
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice');
}

return Status::OK;
Expand Down

0 comments on commit 7c3ade1

Please sign in to comment.