From efd606aff8ce6b1acf1050fa096802669ae8dc83 Mon Sep 17 00:00:00 2001 From: Fabrice Creuzot Date: Tue, 4 Apr 2023 21:52:17 +0200 Subject: [PATCH] Do not translate rules labels --- .../CatalogRule/Model/Rule/Action/Product.php | 8 ++--- .../core/Mage/Rule/Model/Action/Abstract.php | 16 +++++++-- .../Mage/Rule/Model/Condition/Abstract.php | 36 ++++++++++++------- .../Mage/Rule/Model/Condition/Combine.php | 8 ++--- .../SalesRule/Model/Rule/Action/Product.php | 8 ++--- .../Model/Rule/Condition/Product/Found.php | 4 +-- .../Rule/Condition/Product/Subselect.php | 16 ++++----- 7 files changed, 60 insertions(+), 36 deletions(-) diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php index 71bf5c2fe8f..c7e839ec32e 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php @@ -42,10 +42,10 @@ public function loadAttributeOptions() public function loadOperatorOptions() { $this->setOperatorOption([ - 'to_fixed' => Mage::helper('cataloginventory')->__('To Fixed Value'), - 'to_percent' => Mage::helper('cataloginventory')->__('To Percentage'), - 'by_fixed' => Mage::helper('cataloginventory')->__('By Fixed value'), - 'by_percent' => Mage::helper('cataloginventory')->__('By Percentage'), + 'to_fixed' => static::$translate ? Mage::helper('cataloginventory')->__('To Fixed Value') : 'To Fixed Value', + 'to_percent' => static::$translate ? Mage::helper('cataloginventory')->__('To Percentage') : 'To Percentage', + 'by_fixed' => static::$translate ? Mage::helper('cataloginventory')->__('By Fixed value') : 'By Fixed value', + 'by_percent' => static::$translate ? Mage::helper('cataloginventory')->__('By Percentage') : 'By Percentage', ]); return $this; } diff --git a/app/code/core/Mage/Rule/Model/Action/Abstract.php b/app/code/core/Mage/Rule/Model/Action/Abstract.php index 98fb8eda9e5..d6d95a3f02d 100644 --- a/app/code/core/Mage/Rule/Model/Action/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Action/Abstract.php @@ -36,8 +36,20 @@ */ abstract class Mage_Rule_Model_Action_Abstract extends Varien_Object implements Mage_Rule_Model_Action_Interface { + /** + * Flag to enable translation for loadOperatorOptions/loadValueOptions/loadAggregatorOptions/getDefaultOperatorOptions + * It's useless to translate these data on frontend + * + * @var bool + */ + protected static $translate; + public function __construct() { + if (!is_bool(static::$translate)) { + static::$translate = Mage::app()->getStore()->isAdmin(); + } + parent::__construct(); $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); @@ -137,8 +149,8 @@ public function getAttributeName() public function loadOperatorOptions() { $this->setOperatorOption([ - '=' => Mage::helper('rule')->__('to'), - '+=' => Mage::helper('rule')->__('by'), + '=' => static::$translate ? Mage::helper('rule')->__('to') : 'to', + '+=' => static::$translate ? Mage::helper('rule')->__('by') : 'by', ]); return $this; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index c5adabd9ee4..b646b42b314 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -49,6 +49,14 @@ */ abstract class Mage_Rule_Model_Condition_Abstract extends Varien_Object implements Mage_Rule_Model_Condition_Interface { + /** + * Flag to enable translation for loadOperatorOptions/loadValueOptions/loadAggregatorOptions/getDefaultOperatorOptions + * It's useless to translate these data on frontend + * + * @var bool + */ + protected static $translate; + /** * Defines which operators will be available for this condition * @@ -76,6 +84,10 @@ abstract class Mage_Rule_Model_Condition_Abstract extends Varien_Object implemen public function __construct() { + if (!is_bool(static::$translate)) { + static::$translate = Mage::app()->getStore()->isAdmin(); + } + parent::__construct(); $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); @@ -137,18 +149,18 @@ public function getDefaultOperatorOptions() { if ($this->_defaultOperatorOptions === null) { $this->_defaultOperatorOptions = [ - '==' => Mage::helper('rule')->__('is'), - '!=' => Mage::helper('rule')->__('is not'), - '>=' => Mage::helper('rule')->__('equals or greater than'), - '<=' => Mage::helper('rule')->__('equals or less than'), - '>' => Mage::helper('rule')->__('greater than'), - '<' => Mage::helper('rule')->__('less than'), - '{}' => Mage::helper('rule')->__('contains'), - '!{}' => Mage::helper('rule')->__('does not contain'), - '[]' => Mage::helper('rule')->__('contains'), - '![]' => Mage::helper('rule')->__('does not contain'), - '()' => Mage::helper('rule')->__('is one of'), - '!()' => Mage::helper('rule')->__('is not one of') + '==' => static::$translate ? Mage::helper('rule')->__('is') : 'is', + '!=' => static::$translate ? Mage::helper('rule')->__('is not') : 'is not', + '>=' => static::$translate ? Mage::helper('rule')->__('equals or greater than') : 'equals or greater than', + '<=' => static::$translate ? Mage::helper('rule')->__('equals or less than') : 'equals or less than', + '>' => static::$translate ? Mage::helper('rule')->__('greater than') : 'greater than', + '<' => static::$translate ? Mage::helper('rule')->__('less than') : 'less than', + '{}' => static::$translate ? Mage::helper('rule')->__('contains') : 'contains', + '!{}' => static::$translate ? Mage::helper('rule')->__('does not contain') : 'does not contain', + '[]' => static::$translate ? Mage::helper('rule')->__('contains') : 'contains', + '![]' => static::$translate ? Mage::helper('rule')->__('does not contain') : 'does not contain', + '()' => static::$translate ? Mage::helper('rule')->__('is one of') : 'is one of', + '!()' => static::$translate ? Mage::helper('rule')->__('is not one of') : 'is not one of', ]; } return $this->_defaultOperatorOptions; diff --git a/app/code/core/Mage/Rule/Model/Condition/Combine.php b/app/code/core/Mage/Rule/Model/Condition/Combine.php index e4f2f118ac4..4e5807f016f 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Combine.php +++ b/app/code/core/Mage/Rule/Model/Condition/Combine.php @@ -109,8 +109,8 @@ public function __construct() public function loadAggregatorOptions() { $this->setAggregatorOption([ - 'all' => Mage::helper('rule')->__('ALL'), - 'any' => Mage::helper('rule')->__('ANY'), + 'all' => static::$translate ? Mage::helper('rule')->__('ALL') : 'ALL', + 'any' => static::$translate ? Mage::helper('rule')->__('ANY') : 'ANY', ]); return $this; } @@ -161,8 +161,8 @@ public function getAggregatorElement() public function loadValueOptions() { $this->setValueOption([ - 1 => Mage::helper('rule')->__('TRUE'), - 0 => Mage::helper('rule')->__('FALSE'), + 1 => static::$translate ? Mage::helper('rule')->__('TRUE') : 'TRUE', + 0 => static::$translate ? Mage::helper('rule')->__('FALSE') : 'FALSE', ]); return $this; } diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php b/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php index 99ba863e0c0..1a64e771f70 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php @@ -37,10 +37,10 @@ public function loadAttributeOptions() public function loadOperatorOptions() { $this->setOperatorOption([ - 'to_fixed' => Mage::helper('salesrule')->__('To Fixed Value'), - 'to_percent' => Mage::helper('salesrule')->__('To Percentage'), - 'by_fixed' => Mage::helper('salesrule')->__('By Fixed value'), - 'by_percent' => Mage::helper('salesrule')->__('By Percentage'), + 'to_fixed' => static::$translate ? Mage::helper('salesrule')->__('To Fixed Value') : 'To Fixed Value', + 'to_percent' => static::$translate ? Mage::helper('salesrule')->__('To Percentage') : 'To Percentage', + 'by_fixed' => static::$translate ? Mage::helper('salesrule')->__('By Fixed value') : 'By Fixed value', + 'by_percent' => static::$translate ? Mage::helper('salesrule')->__('By Percentage') : 'By Percentage', ]); return $this; } diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php index d3e89adb252..6614c4e7ca2 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php @@ -38,8 +38,8 @@ public function __construct() public function loadValueOptions() { $this->setValueOption([ - 1 => Mage::helper('salesrule')->__('FOUND'), - 0 => Mage::helper('salesrule')->__('NOT FOUND') + 1 => static::$translate ? Mage::helper('salesrule')->__('FOUND') : 'FOUND', + 0 => static::$translate ? Mage::helper('salesrule')->__('NOT FOUND') : 'NOT FOUND', ]); return $this; } diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php index 6abf2cb82bd..4a0d000addd 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php @@ -83,14 +83,14 @@ public function loadValueOptions() public function loadOperatorOptions() { $this->setOperatorOption([ - '==' => Mage::helper('rule')->__('is'), - '!=' => Mage::helper('rule')->__('is not'), - '>=' => Mage::helper('rule')->__('equals or greater than'), - '<=' => Mage::helper('rule')->__('equals or less than'), - '>' => Mage::helper('rule')->__('greater than'), - '<' => Mage::helper('rule')->__('less than'), - '()' => Mage::helper('rule')->__('is one of'), - '!()' => Mage::helper('rule')->__('is not one of'), + '==' => static::$translate ? Mage::helper('rule')->__('is') : 'is', + '!=' => static::$translate ? Mage::helper('rule')->__('is not') : 'is not', + '>=' => static::$translate ? Mage::helper('rule')->__('equals or greater than') : 'equals or greater than', + '<=' => static::$translate ? Mage::helper('rule')->__('equals or less than') : 'equals or less than', + '>' => static::$translate ? Mage::helper('rule')->__('greater than') : 'greater than', + '<' => static::$translate ? Mage::helper('rule')->__('less than') : 'less than', + '()' => static::$translate ? Mage::helper('rule')->__('is one of') : 'is one of', + '!()' => static::$translate ? Mage::helper('rule')->__('is not one of') : 'is not one of', ]); return $this; }