Skip to content

Commit

Permalink
Merge pull request #6 from web-vision/task/upgrade-v10
Browse files Browse the repository at this point in the history
[TASK] Upgrade to version 10 LTS
  • Loading branch information
rickymathewkweb authored Apr 27, 2020
2 parents 84694c1 + 8469233 commit 5f776e4
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 93 deletions.
38 changes: 2 additions & 36 deletions Classes/Hooks/TranslateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ public function processTranslateTo_copyAction(&$content, $languageRecord, $dataH

} else {
$currentRecord = BackendUtility::getRecord($tablename, (int) $currectRecordId);
$selectedTCAvalues = $this->getTemplateValues($currentRecord, $tablename, $field, $content);

if (!empty($selectedTCAvalues)) {
$response = $this->deeplService->translateRequest($selectedTCAvalues, $targetLanguage['language_isocode'], $sourceLanguage['language_isocode']);
}
$response = $this->deeplService->translateRequest($content, $targetLanguage['language_isocode'], $sourceLanguage['language_isocode']);
}
if (!empty($response) && isset($response->translations)) {
foreach ($response->translations as $translation) {
Expand All @@ -164,11 +160,7 @@ public function processTranslateTo_copyAction(&$content, $languageRecord, $dataH

} else {
$currentRecord = BackendUtility::getRecord($tablename, (int) $currectRecordId);
$selectedTCAvalues = $this->getTemplateValues($currentRecord, $tablename, $field, $content);

if (!empty($selectedTCAvalues)) {
$response = $this->googleService->translate($sourceLanguage['language_isocode'], $targetLanguage['language_isocode'], $selectedTCAvalues);
}
$response = $this->googleService->translate($content, $targetLanguage['language_isocode'], $content);
}
if (!empty($response)) {
if ($this->isHtml($response)) {
Expand Down Expand Up @@ -236,30 +228,4 @@ public function stripSpecificTags($tags, $content)
return $content;
}

/**
* Returns default content of records according to the typoscript setting from typoscript
* @param array $recorddata
* @param string $table
* @param string $field
* @return void
*/
public function getTemplateValues($recorddata, $table, $field, $content)
{
$rootLineUtility = GeneralUtility::makeInstance('TYPO3\CMS\Core\Utility\RootlineUtility',$recorddata['pid']);
$rootLine = $rootLineUtility->get();
$TSObj = GeneralUtility::makeInstance('TYPO3\CMS\Core\TypoScript\TemplateService');
$TSObj->tt_track = 0;
$TSObj->init();
$TSObj->runThroughTemplates($rootLine);
$TSObj->generateConfig();
if ($table != '') {
$fieldlist = $TSObj->setup['plugin.'][$table . '.']['translatableTCAvalues'];
if ($fieldlist != null && strpos($fieldlist, $field) !== false) {
$value = $this->deeplSettingsRepository->getRecordField($table, $field, $recorddata);
} else {
return $content;
}
}
}

}
4 changes: 1 addition & 3 deletions Classes/Override/LocalizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,12 @@ protected function process($params): void
/**
* check deepl Settings (url,apikey).
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return array
*/
public function checkdeeplSettings(ServerRequestInterface $request, ResponseInterface $response)
public function checkdeeplSettings(ServerRequestInterface $request)
{
$this->deeplService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('WebVision\\WvDeepltranslate\\Service\\DeeplService');
$result = [];
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['wv_deepltranslate']);
if ($this->deeplService->apiKey != null && $this->deeplService->apiUrl != null) {
$result['status'] = 'true';
} else {
Expand Down
3 changes: 2 additions & 1 deletion Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use WebVision\WvDeepltranslate\Domain\Repository\DeeplSettingsRepository;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;

class DeeplService
{
Expand Down Expand Up @@ -73,7 +74,7 @@ class DeeplService
*/
public function __construct()
{
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['wv_deepltranslate']);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('wv_deepltranslate');

$this->deeplSettingsRepository = GeneralUtility::makeInstance(DeeplSettingsRepository::class);
$this->requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
Expand Down
3 changes: 2 additions & 1 deletion Classes/Service/GoogleTranslateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use GuzzleHttp\Exception\ClientException;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;

class GoogleTranslateService
{
Expand All @@ -57,7 +58,7 @@ class GoogleTranslateService
public function __construct()
{
$this->requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['wv_deepltranslate']);
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('wv_deepltranslate');
$this->apiUrl = $extConf['googleapiUrl'];
$this->apiKey = $extConf['googleapiKey'];
}
Expand Down
19 changes: 19 additions & 0 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
defined('TYPO3_MODE') || die();

call_user_func(function()
{
/**
* Temporary variables
*/
$extensionKey = 'wv_deepltranslate';

/**
* Default TypoScript for wv_deepltranslate
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
$extensionKey,
'Configuration/TypoScript',
'wv_deepltranslate'
);
});
Loading

0 comments on commit 5f776e4

Please sign in to comment.