Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Inline translation block
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Nov 8, 2014
1 parent 9ea5611 commit a0a1bfd
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
88 changes: 88 additions & 0 deletions app/code/community/MKleine/LanguageRoutes/Block/Translate/Uri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

class MKleine_LanguageRoutes_Block_Translate_Uri extends Mage_Core_Block_Template
{
public function __construct(array $args = array())
{
parent::__construct($args);
$this->setTemplate('mkleine/languageroutes/translate/uri.phtml');
}

/**
* Returns the action to the admin form controller
*
* @return string
*/
public function getFormAction()
{
return Mage::getModel('adminhtml/url')->getUrl('adminhtml/languageroute/saveinline');
}

/**
* Checks, if the current user is allowed to translate the current url
*
* @return bool
*/
public function isAllowed()
{
/** @var $translate Mage_Core_Model_Translate_Inline */
$translate = Mage::getSingleton('core/translate_inline');
return $translate->isAllowed();
}

/**
* @param bool $translate
* @return MKleine_LanguageRoutes_Model_Core_Url
*/
protected function getUrlModel($translate = true)
{
return Mage::getModel('core/url')
->setRoutePath('*/*/*')
->setNoTranslate(!$translate);
}

/**
* Returns the translation of the current route
* @return string
*/
public function getValueRoute()
{
$value = $this->getUrlModel()->getRouteFrontName();
return ($value != $this->getUntranslatedRoute()) ? $value : '';
}

public function getUntranslatedRoute()
{
return $this->getUrlModel(false)->getRouteFrontName();
}

/**
* Returns the translation of the current controller
* @return string
*/
public function getValueController()
{
$value = $this->getUrlModel()->getControllerName();
return ($value != $this->getUntranslatedController()) ? $value : '';
}

public function getUntranslatedController()
{
return $this->getUrlModel(false)->getControllerName();
}

/**
* Returns the translation of the current action
* @return string
*/
public function getValueAction()
{
$value = $this->getUrlModel()->getActionName();
return ($value != $this->getUntranslatedAction()) ? $value : '';
}

public function getUntranslatedAction()
{
return $this->getUrlModel(false)->getActionName();
}
}
7 changes: 7 additions & 0 deletions app/code/community/MKleine/LanguageRoutes/Model/Core/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
* @copyright Copyright (c) 2014 Matthias Kleine (http://mkleine.de)
* @license http://opensource.org/licenses/MIT MIT
*/

/**
* Class MKleine_LanguageRoutes_Model_Core_Url
*
* @method setNoTranslate
* @method getNoTranslate
*/
class MKleine_LanguageRoutes_Model_Core_Url extends Mage_Core_Model_Url
{
/**
Expand Down
24 changes: 24 additions & 0 deletions app/code/community/MKleine/LanguageRoutes/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ public function controllerActionLayoutRenderBefore($observer)
}
}

/**
* Adds translation block for current url
*
* @param $observer Varien_Event_Observer
*/
public function controllerActionLayoutGenerateBlocksAfter($observer)
{
/** @var $translate Mage_Core_Model_Translate_Inline */
$translate = Mage::getSingleton('core/translate_inline');
if ($translate->isAllowed()) {
/** @var $layout Mage_Core_Model_Layout */
$layout = $observer->getLayout();

if ($contentBlock = $layout->getBlock('content')) {
$translateBlock = $layout->createBlock(
'mk_languageroutes/translate_uri',
'languageroutes_inline_translate_uri'
);

$contentBlock->append($translateBlock);
}
}
}

/**
* Forward the client to the translated url if configured
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,31 @@ public function valuesAction()
$this->getResponse()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}

/**
* Controller to save information
*/
public function saveinlineAction()
{
$returlUrl = $this->getRequest()->getParam('current_url', false);
$storeId = $this->getRequest()->getParam('store_id', false);

$routeT = $this->getRequest()->getParam('route', false);
$routeU = $this->getRequest()->getParam('route_untranslated', false);

$controllerT = $this->getRequest()->getParam('controller', false);
$controllerU = $this->getRequest()->getParam('controller_untranslated', false);

$actionT = $this->getRequest()->getParam('action', false);
$actionU = $this->getRequest()->getParam('action_untranslated', false);

// TODO: Insert or replace information

if ($returlUrl) {
$this->_redirectUrl($returlUrl);
}
else {
$this->_redirect('*/*/index');
}
}
}
9 changes: 9 additions & 0 deletions app/code/community/MKleine/LanguageRoutes/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
</mk_languageroutes>
</observers>
</controller_action_layout_render_before>
<controller_action_layout_generate_blocks_after>
<observers>
<mk_languageroutes>
<class>mk_languageroutes/observer</class>
<type>singleton</type>
<method>controllerActionLayoutGenerateBlocksAfter</method>
</mk_languageroutes>
</observers>
</controller_action_layout_generate_blocks_after>
<controller_action_predispatch>
<observers>
<mk_languageroutes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php /** @var $this MKleine_LanguageRoutes_Block_Translate_Uri */ ?>

<?php if ($this->isAllowed()) : ?>
<div class="block block-translate" id="languageroute-translation" style="position: absolute; top: 10px; left: 10px; z-index: 1000;">
<div class="block-title">
<strong><span><?php echo $this->__('Translate Uri'); ?></span></strong>
</div>
<form id="languageRouteForm" action="<?php echo $this->getFormAction(); ?>" method="post">
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Route'); ?> (<?php echo $this->getUntranslatedRoute(); ?>)</p>
<input type="text" name="route" value="<?php echo $this->getValueRoute(); ?>">
<input type="hidden" name="route_untranslated" value="<?php echo $this->getUntranslatedRoute(); ?>">

<p class="block-subtitle"><?php echo $this->__('Controller'); ?> (<?php echo $this->getUntranslatedController(); ?>)</p>
<input type="text" name="controller" value="<?php echo $this->getValueController(); ?>">
<input type="hidden" name="controller_untranslated" value="<?php echo $this->getUntranslatedController(); ?>">

<p class="block-subtitle"><?php echo $this->__('Action'); ?> (<?php echo $this->getUntranslatedAction(); ?>)</p>
<input type="text" name="action" value="<?php echo $this->getValueAction(); ?>">
<input type="hidden" name="action_untranslated" value="<?php echo $this->getUntranslatedAction(); ?>">

<input type="hidden" name="store_id" value="<?php echo Mage::app()->getStore()->getId() ?>">
<input type="hidden" name="current_url" value="<?php echo Mage::getUrl('*/*/*') ?>">
<div class="actions">
<button type="submit" title="Abstimmen" class="button"><span><span><?php echo $this->__('Save'); ?></span></span></button>
</div>
</div>
</form>
</div>
<?php endif; ?>
1 change: 1 addition & 0 deletions modman
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
app/code/community/MKleine/* app/code/community/MKleine/
app/etc/modules/* app/etc/modules/
app/design/adminhtml/default/default/layout/* app/design/adminhtml/default/default/layout/
app/design/frontend/base/default/template/mkleine/* app/design/frontend/base/default/template/mkleine/
app/locale/de_DE/* app/locale/de_DE/
app/locale/en_US/* app/locale/en_US/

0 comments on commit a0a1bfd

Please sign in to comment.