Skip to content

Instantly share code, notes, and snippets.

@mneuhaus
Created October 12, 2015 18:00
Show Gist options
  • Save mneuhaus/1db70e1f43eb4728b5e5 to your computer and use it in GitHub Desktop.
Save mneuhaus/1db70e1f43eb4728b5e5 to your computer and use it in GitHub Desktop.
<?php
namespace AWESOME\Translation\ViewHelpers;
/* *
* This script belongs to the TYPO3 Flow package "Flowpack.Expose". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use AWESOME\Translation\Service\TranslationService;
use Doctrine\ORM\Mapping as ORM;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
*/
class TranslateViewHelper extends AbstractViewHelper {
/**
* NOTE: This property has been introduced via code migration to ensure backwards-compatibility.
* @see AbstractViewHelper::isOutputEscapingEnabled()
* @var boolean
*/
protected $escapeOutput = FALSE;
/**
* @var TranslationService
* @Flow\Inject
*/
protected $translationService;
/**
*
* @param string $contextPath
* @param string $source
* @param string $sourceLanguage
* @param string $as
* @return string Rendered string
* @api
*/
public function render($contextPath, $source, $sourceLanguage = NULL, $as = NULL) {
$translation = $this->translationService->getTranslation($contextPath, $source);
if ($as === NULL) {
return $translation;
}
$templateVariableContainer = $this->renderingContext->getTemplateVariableContainer();
$templateVariableContainer->add($as, $translation);
$output = $this->renderChildren();
$templateVariableContainer->remove($as);
return $output;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment