Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@
- BO/FO : Accessibility improvements for EAA / WCAG 2.1 AA compliance
- Added configurable payment description and order reference on payment page
- API update to V1.50: added WERO and GIFTCARD payment methods, removed deprecated GIROPAY/PAYDIREKT/SOFORT
- BO/FO : Added German and French translations for all module texts
- BO : Fixed issue when the module menu tabs stayed in English on German and French shops
- BO : Fixed issue when a freshly installed module logged an account error before any API credentials were entered
- BO : Fixed issue when the "Could not reach your Saferpay account" warning kept showing after payment methods had loaded successfully
- Fixed issue when files removed in this version stayed on disk after an upgrade, leaving obsolete iframe checkout controllers reachable and re-creating obsolete menu tabs on module reset
Expand Down
76 changes: 72 additions & 4 deletions src/Install/AbstractInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Invertus\SaferPay\Install;

use Language;
use SaferPayOfficial;

if (!defined('_PS_VERSION_')) {
Expand All @@ -36,6 +37,11 @@ abstract class AbstractInstaller
*/
protected $module;

/**
* @var array|null
*/
private $dictionaries;

public function __construct(SaferPayOfficial $module)
{
$this->module = $module;
Expand All @@ -51,31 +57,93 @@ public function tabs()
'visible' => false,
],
[
'name' => $this->module->l('Settings'),
'name' => $this->tabName('Settings'),
'class_name' => SaferPayOfficial::ADMIN_SETTINGS_CONTROLLER,
'parent_class_name' => SaferPayOfficial::ADMIN_SAFERPAY_MODULE_CONTROLLER,
'module_tab' => true,
],
[
'name' => $this->module->l('Payments'),
'name' => $this->tabName('Payments'),
'class_name' => SaferPayOfficial::ADMIN_PAYMENTS_CONTROLLER,
'parent_class_name' => SaferPayOfficial::ADMIN_SAFERPAY_MODULE_CONTROLLER,
'module_tab' => true,
'visible' => false,
],
[
'name' => $this->module->l('Order'),
'name' => $this->tabName('Order'),
'class_name' => SaferPayOfficial::ADMIN_ORDER_CONTROLLER,
'parent_class_name' => SaferPayOfficial::ADMIN_SAFERPAY_MODULE_CONTROLLER,
'module_tab' => true,
'visible' => false,
],
[
'name' => $this->module->l('Logs'),
'name' => $this->tabName('Logs'),
'class_name' => SaferPayOfficial::ADMIN_LOGS_CONTROLLER,
'parent_class_name' => SaferPayOfficial::ADMIN_SAFERPAY_MODULE_CONTROLLER,
'module_tab' => true,
],
];
}

/**
* A tab name is stored once per language, so every language has to be resolved while the tab
* is created instead of once in the language of the employee installing the module.
*
* Module::l() cannot do that here. getModuleTranslation() merges every dictionary it loads
* into one global $_MODULES, and the keys are identical in all languages, so the file loaded
* last wins. A language the module ships no wording for would then take the previous
* language's value instead of falling back to English. Reading the dictionaries keeps every
* language independent of that load order.
*
* English stays first in the returned map because ModuleTabRegister::getTabNames() falls back
* to the first entry for any language missing from it.
*
* @param string $source
*
* @return array
*/
protected function tabName($source)
{
$names = ['en' => $source];
$key = '<{' . $this->module->name . '}prestashop>' . $this->module->name . '_' . md5($source);

foreach ($this->getDictionaries() as $iso => $dictionary) {
if (empty($dictionary[$key])) {
continue;
}

$names[$iso] = $dictionary[$key];
}

return $names;
}

/**
* @return array
*/
private function getDictionaries()
{
if ($this->dictionaries !== null) {
return $this->dictionaries;
}

$this->dictionaries = [];
$current = isset($GLOBALS['_MODULE']) ? $GLOBALS['_MODULE'] : [];

foreach (Language::getLanguages(false) as $language) {
$file = _PS_MODULE_DIR_ . $this->module->name . '/translations/' . $language['iso_code'] . '.php';

if (!is_readable($file)) {
continue;
}

$GLOBALS['_MODULE'] = [];
include $file;
$this->dictionaries[$language['iso_code']] = $GLOBALS['_MODULE'];
}

$GLOBALS['_MODULE'] = $current;

return $this->dictionaries;
}
}
2 changes: 1 addition & 1 deletion src/Service/LegacyTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function getTranslations(): array
SaferPayConfig::PAYMENT_POSTFINANCE_PAY => $this->module->l('PostFinancePay', self::FILE_NAME),
SaferPayConfig::PAYMENT_WECHATPAY => $this->module->l('WeChatPay', self::FILE_NAME),
SaferPayConfig::PAYMENT_BLIK => $this->module->l('Blik', self::FILE_NAME),
SaferPayConfig::PAYMENT_GOOGLEPAY => $this->module->l('Googlepay'),
SaferPayConfig::PAYMENT_GOOGLEPAY => $this->module->l('Googlepay', self::FILE_NAME),
SaferPayConfig::PAYMENT_CLICKTOPAY => $this->module->l('Clicktopay', self::FILE_NAME),
SaferPayConfig::PAYMENT_REKA => $this->module->l('Reka', self::FILE_NAME),
SaferPayConfig::PAYMENT_WERO => $this->module->l('Wero', self::FILE_NAME),
Expand Down
Loading
Loading