[FEATURE] Add backend for loading translations via ajax

This commit is contained in:
2024-02-09 11:04:01 +01:00
parent e126e674c7
commit ddbb0c35b0
22 changed files with 625 additions and 69 deletions

View File

@@ -141,6 +141,11 @@ class ActionController extends BaseController
*/
protected $propertyMapperConfigurationBuilder;
/**
* translation extensions
*/
protected $translations = [];
/**
* @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService
*/
@@ -616,10 +621,26 @@ class ActionController extends BaseController
$this->request->getControllerActionName(),
$pluginArguments
);
$uriTranslation = $this->getControllerContext()
->getUriBuilder()
->reset()
->setCreateAbsoluteUri(true)
->setAddQueryString(true)
->setTargetPageType(6001)
->uriFor(
'translations',
[
'extensions' => $this->translations,
],
'Translation',
'TemplatesAide',
'Translationplugin'
);
$this->ajaxEnv = [
'uri' => $uri,
'object' => $object,
'namespace' => $this->getPluginNamespace(),
'uri' => $uri,
'uriTranslation' => $uriTranslation,
'object' => $object,
'namespace' => $this->getPluginNamespace(),
];
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Cjel\TemplatesAide\Controller;
/***
*
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2024 Philipp Dieter <philippdieter@attic-media.net>
*
***/
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* TranslationController
*/
class TranslationController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
protected static $locallangPath = 'Resources/Private/Language/';
/**
* action translations
*
* @param array $extensions
* @return void
*/
public function translationsAction($extensions = [])
{
$result = [];
foreach ($extensions as $extension) {
$langfilePath = 'EXT:'
. GeneralUtility::camelCaseToLowerCaseUnderscored($extension)
. '/'
. self::$locallangPath
. 'locallang.xlf';
$languageFactory = GeneralUtility::makeInstance(
LocalizationFactory::class
);
$langfileContent = $languageFactory->getParsedData(
$langfilePath,
$GLOBALS['LANG']->lang
);
$langfileResult = [];
foreach (reset($langfileContent) as $key => $row) {
$langfileResult[$key] = reset($row)['target'];
}
$result[$extension] = $langfileResult;
}
$GLOBALS['TSFE']->setContentType('application/json');
return json_encode($result);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Cjel\TemplatesAide\Domain\Model;
/***
*
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2024 Philipp Dieter <philippdieter@attic-media.net>
*
***/
/**
* Translation
*/
class Translation extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
}