Skip to content

Commit

Permalink
Fixed the wording translation for Enable/Disable Mobile in Modules page
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Apr 1, 2022
1 parent 1159012 commit 324b625
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
45 changes: 35 additions & 10 deletions src/Adapter/Module/AdminModuleDataProvider.php
Expand Up @@ -49,21 +49,45 @@ class AdminModuleDataProvider implements ModuleInterface
* @const array giving a translation domain key for each module action
*/
public const _ACTIONS_TRANSLATION_DOMAINS_ = [
'install' => 'Admin.Actions',
'uninstall' => 'Admin.Actions',
'enable' => 'Admin.Actions',
'disable' => 'Admin.Actions',
'enableMobile' => 'Admin.Modules.Feature',
'disableMobile' => 'Admin.Modules.Feature',
'reset' => 'Admin.Actions',
'upgrade' => 'Admin.Actions',
'configure' => 'Admin.Actions',
Module::ACTION_INSTALL => 'Admin.Actions',
Module::ACTION_UNINSTALL => 'Admin.Actions',
Module::ACTION_ENABLE => 'Admin.Actions',
Module::ACTION_DISABLE => 'Admin.Actions',
Module::ACTION_ENABLE_MOBILE => 'Admin.Modules.Feature',
Module::ACTION_DISABLE_MOBILE => 'Admin.Modules.Feature',
Module::ACTION_RESET => 'Admin.Actions',
Module::ACTION_UPGRADE => 'Admin.Actions',
Module::ACTION_CONFIGURE => 'Admin.Actions',
];

/**
* @const array giving a translation label for each module action
*/
public const ACTIONS_TRANSLATION_LABELS = [
Module::ACTION_INSTALL => 'Install',
Module::ACTION_UNINSTALL => 'Uninstall',
Module::ACTION_ENABLE => 'Enable',
Module::ACTION_DISABLE => 'Disable',
Module::ACTION_ENABLE_MOBILE => 'Enable mobile',
Module::ACTION_DISABLE_MOBILE => 'Disable mobile',
Module::ACTION_RESET => 'Reset',
Module::ACTION_UPGRADE => 'Upgrade',
Module::ACTION_CONFIGURE => 'Configure',
];

/**
* @var array of defined and callable module actions
*/
protected $moduleActions = ['install', 'uninstall', 'enable', 'disable', 'enableMobile', 'disableMobile', 'reset', 'upgrade'];
protected $moduleActions = [
Module::ACTION_INSTALL,
Module::ACTION_UNINSTALL,
Module::ACTION_ENABLE,
Module::ACTION_DISABLE,
Module::ACTION_ENABLE_MOBILE,
Module::ACTION_DISABLE_MOBILE,
Module::ACTION_RESET,
Module::ACTION_UPGRADE,
];

/**
* @var Router|null
Expand Down Expand Up @@ -255,6 +279,7 @@ public function generateAddonsUrls(AddonsCollection $addons, $specific_action =
$urls = $this->filterAllowedActions($urls, $addon->attributes->get('name'));
$addon->attributes->set('urls', $urls);
$addon->attributes->set('actionTranslationDomains', self::_ACTIONS_TRANSLATION_DOMAINS_);
$addon->attributes->set('actionTranslationLabels', self::ACTIONS_TRANSLATION_LABELS);
if ($specific_action && array_key_exists($specific_action, $urls)) {
$addon->attributes->set('url_active', $specific_action);
} elseif ($url_active === 'buy' || array_key_exists($url_active, $urls)) {
Expand Down
1 change: 1 addition & 0 deletions src/Adapter/Module/Module.php
Expand Up @@ -47,6 +47,7 @@ class Module implements ModuleInterface
public const ACTION_DISABLE_MOBILE = 'disableMobile';
public const ACTION_RESET = 'reset';
public const ACTION_UPGRADE = 'upgrade';
public const ACTION_CONFIGURE = 'configure';

/**
* @var LegacyModule Module The instance of the legacy module
Expand Down
3 changes: 2 additions & 1 deletion src/PrestaShopBundle/Command/ModuleCommand.php
Expand Up @@ -28,6 +28,7 @@

use Employee;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider;
use PrestaShop\PrestaShop\Adapter\Module\Configuration\ModuleSelfConfigurator;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManager;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -190,7 +191,7 @@ protected function executeGenericModuleAction($action, $moduleName)
$this->translator->trans(
'%action% action on module %module% succeeded.',
[
'%action%' => ucfirst(str_replace('_', ' ', $action)),
'%action%' => ucfirst(AdminModuleDataProvider::ACTIONS_TRANSLATION_LABELS[$action]),
'%module%' => $moduleName, ],
'Admin.Modules.Notification'
)
Expand Down
Expand Up @@ -224,7 +224,7 @@ public function moduleAction(Request $request)
return new JsonResponse($response);
}

$actionTitle = str_replace('_', ' ', $action);
$actionTitle = AdminModuleDataProvider::ACTIONS_TRANSLATION_LABELS[$action];

try {
$response[$module]['status'] = $moduleManager->{$action}($module);
Expand Down
Expand Up @@ -23,7 +23,7 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*#}

{% set displayAction = action|title|replace({'_': " "})|trans({}, transDomain[action]) %}
{% set displayAction = transLabels[action]|title|trans({}, transDomain[action]) %}

{% if (action == 'configure') %}

Expand Down
Expand Up @@ -22,13 +22,14 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*#}
{% set url, priceRaw, priceDisplay, url_active, urls, name, transDomains =
{% set url, priceRaw, priceDisplay, url_active, urls, name, transLabels, transDomains =
module.attributes.url,
module.attributes.price.raw,
module.attributes.price.displayPrice,
module.attributes.url_active,
module.attributes.urls,
module.attributes.name,
module.attributes.actionTranslationLabels,
module.attributes.actionTranslationDomains
%}
<div class="btn-group module-actions">
Expand All @@ -43,14 +44,15 @@
'classes' : 'btn btn-primary-reverse btn-outline-primary',
'url': urls[url_active],
'action': url_active,
'transLabels': transLabels,
'transDomain': transDomains}
%}
{% if (urls|length > 1) %}
<input type="hidden" class="btn" />
<button type="button" class="btn btn-outline-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<input type="hidden" class="btn" />
<button type="button" class="btn btn-outline-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
<span class="sr-only">{{ 'Toggle Dropdown'|trans({}, 'Admin.Modules.Feature') }}</span>
<span class="sr-only">{{ 'Toggle Dropdown'|trans({}, 'Admin.Modules.Feature') }}</span>
<div class="dropdown-menu">
{% for module_action, module_url in urls %}
{% if module_action != url_active %}
Expand All @@ -60,6 +62,7 @@
'classes' : 'dropdown-item',
'url': module_url,
'action': module_action,
'transLabels': transLabels,
'transDomain': transDomains}
%}
</li>
Expand Down

0 comments on commit 324b625

Please sign in to comment.