Skip to content

Instantly share code, notes, and snippets.

@nezaniel
Last active August 29, 2015 14:21
Show Gist options
  • Save nezaniel/ff1408ffa3d99e3075b3 to your computer and use it in GitHub Desktop.
Save nezaniel/ff1408ffa3d99e3075b3 to your computer and use it in GitHub Desktop.
Neos Backend xliff provider with configurable override
<?php
namespace TYPO3\Neos\Controller\Backend;
/* *
* This script belongs to the TYPO3 Flow package "TYPO3.Neos". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License, either version 3 of the *
* License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\I18n\Locale;
use TYPO3\Flow\Utility\Arrays;
/**
* The TYPO3 Backend controller
*
* @Flow\Scope("singleton")
*/
class BackendController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* @Flow\Inject
* @var \TYPO3\Neos\Service\BackendRedirectionService
*/
protected $backendRedirectionService;
/**
* @Flow\Inject
* @var \TYPO3\Neos\Service\XliffService
*/
protected $xliffService;
/**
* @Flow\Inject
* @var \TYPO3\Neos\Service\UserService
*/
protected $userService;
/**
* @Flow\Inject(setting="ui.translation.autoInclude", package="TYPO3.Neos")
* @var array
*/
protected $packagesRegisteredForAutoInclusion = [];
/**
* Default action of the backend controller.
*
* @return void
*/
public function indexAction() {
$redirectionUri = $this->backendRedirectionService->getAfterLoginRedirectionUri($this->request);
if ($redirectionUri === NULL) {
$redirectionUri = $this->uriBuilder->uriFor('index', array(), 'Login', 'TYPO3.Neos');
}
$this->redirectToUri($redirectionUri);
}
/**
* Returns the cached json array with the xliff labels
*
* @return string
*/
public function getXliffAsJsonAction() {
$this->response->setHeader('Content-Type', 'application/json');
$locale = new Locale($this->userService->getInterfaceLanguage());
$labels = json_decode($this->xliffService->getCachedJson($locale), TRUE);
foreach ($this->packagesRegisteredForAutoInclusion as $packageKey => $isToBeIncluded) {
if ($isToBeIncluded === TRUE) {
$overrideLabels = json_decode($this->xliffService->getCachedJson($locale, 'Main', $packageKey), TRUE);
$overrideLabels = Arrays::getValueByPath($overrideLabels, $packageKey);
if (isset($overrideLabels['Main'])) {
$labels['TYPO3']['Neos']['Main'] = Arrays::arrayMergeRecursiveOverrule($labels['TYPO3']['Neos']['Main'], $overrideLabels['Main']);
}
}
}
return json_encode($labels);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment