From e0d18785d4528de5728d6a3a7e4fed9ed46e36dc Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 26 Dec 2014 11:17:43 -0300 Subject: [PATCH 1/3] refs ability to add Translation for CMS page and CMS block. --- .../System/Variable/WysiwygPlugin.php | 8 +++++--- app/code/Magento/Core/Model/Variable.php | 20 +++++++++++++++++++ .../Magento/Widget/Model/Template/Filter.php | 14 +++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php index 31dd38503634a..d98f64e965105 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php @@ -13,15 +13,17 @@ class WysiwygPlugin extends \Magento\Backend\Controller\Adminhtml\System\Variabl * @return \Magento\Framework\Controller\Result\JSON */ public function execute() - { - $customVariables = $this->_objectManager->create('Magento\Core\Model\Variable')->getVariablesOptionArray(true); + { + $objectManager = $this->_objectManager->create('Magento\Core\Model\Variable'); + $customVariables = $objectManager->getVariablesOptionArray(true); $storeContactVariabls = $this->_objectManager->create( 'Magento\Email\Model\Source\Variables' )->toOptionArray( true ); + $translateVariables = $objectManager->getTranslateVariablesOptionArray(true); /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ $resultJson = $this->resultJsonFactory->create(); - return $resultJson->setData([$storeContactVariabls, $customVariables]); + return $resultJson->setData([$storeContactVariabls, $customVariables, $translateVariables]); } } diff --git a/app/code/Magento/Core/Model/Variable.php b/app/code/Magento/Core/Model/Variable.php index 725d458de080a..7d95952ff7da5 100644 --- a/app/code/Magento/Core/Model/Variable.php +++ b/app/code/Magento/Core/Model/Variable.php @@ -136,6 +136,26 @@ public function validate() return __('Validation has failed.'); } + /* Retrieve translation option + * + * @param bool $withGroup + * @return array + */ + public function getTranslateVariablesOptionArray($withGroup = false) + { + $optionArray[] = array( + 'value' => '{{translate text=""}}', + 'label' => "Translate string" + ); + if ($withGroup && $optionArray) { + $optionArray = array( + 'label' => __('Translation'), + 'value' => $optionArray + ); + } + return $optionArray; + } + /** * Retrieve variables option array * @todo: extract method as separate class diff --git a/app/code/Magento/Widget/Model/Template/Filter.php b/app/code/Magento/Widget/Model/Template/Filter.php index e5c7aa30374b2..78ab9a736d76a 100644 --- a/app/code/Magento/Widget/Model/Template/Filter.php +++ b/app/code/Magento/Widget/Model/Template/Filter.php @@ -107,4 +107,18 @@ public function widgetDirective($construction) return $widget->toHtml(); } + + /** + * Generate translatable text + * + * @param array $construction + * @return string + */ + public function translateDirective($construction) + { + $params = $this->_getIncludeParameters($construction[2]); + $text = $params['text']; + return __($text); + } + } From 25828bea2e61485fd1b0482a62bc819158527de0 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 26 Dec 2014 21:16:13 -0300 Subject: [PATCH 2/3] refs ability to add Translation for CMS page and CMS block. Fixing tests. --- .../System/Variable/WysiwygPlugin.php | 2 +- app/code/Magento/Core/Model/Variable.php | 18 +++++++++--------- .../Magento/Widget/Model/Template/Filter.php | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php index d98f64e965105..3b0c0030dad10 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php @@ -26,4 +26,4 @@ public function execute() $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData([$storeContactVariabls, $customVariables, $translateVariables]); } -} +} \ No newline at end of file diff --git a/app/code/Magento/Core/Model/Variable.php b/app/code/Magento/Core/Model/Variable.php index 7d95952ff7da5..67c491da12df2 100644 --- a/app/code/Magento/Core/Model/Variable.php +++ b/app/code/Magento/Core/Model/Variable.php @@ -136,25 +136,25 @@ public function validate() return __('Validation has failed.'); } - /* Retrieve translation option - * + /** + * Retrieve translation option * @param bool $withGroup * @return array */ - public function getTranslateVariablesOptionArray($withGroup = false) - { - $optionArray[] = array( + public function getTranslateVariablesOptionArray($withGroup = false) + { + $optionArray[] = [ 'value' => '{{translate text=""}}', 'label' => "Translate string" - ); + ]; if ($withGroup && $optionArray) { - $optionArray = array( + $optionArray = [ 'label' => __('Translation'), 'value' => $optionArray - ); + ]; } return $optionArray; - } + } /** * Retrieve variables option array diff --git a/app/code/Magento/Widget/Model/Template/Filter.php b/app/code/Magento/Widget/Model/Template/Filter.php index 78ab9a736d76a..72ef2985bb9c3 100644 --- a/app/code/Magento/Widget/Model/Template/Filter.php +++ b/app/code/Magento/Widget/Model/Template/Filter.php @@ -120,5 +120,4 @@ public function translateDirective($construction) $text = $params['text']; return __($text); } - } From bad3e0029de6655bd35970263c826db9e0daa19d Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 26 Dec 2014 22:48:54 -0300 Subject: [PATCH 3/3] refs ability to add Translation for CMS page and CMS block. Fixing tests. --- .../Controller/Adminhtml/System/Variable/WysiwygPlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php index 3b0c0030dad10..54342e907d21e 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Variable/WysiwygPlugin.php @@ -13,7 +13,7 @@ class WysiwygPlugin extends \Magento\Backend\Controller\Adminhtml\System\Variabl * @return \Magento\Framework\Controller\Result\JSON */ public function execute() - { + { $objectManager = $this->_objectManager->create('Magento\Core\Model\Variable'); $customVariables = $objectManager->getVariablesOptionArray(true); $storeContactVariabls = $this->_objectManager->create( @@ -26,4 +26,4 @@ public function execute() $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData([$storeContactVariabls, $customVariables, $translateVariables]); } -} \ No newline at end of file +}